简体   繁体   中英

onSaveInstanceState is not called on orientation change before onDestroy() to save data during orientation change

I am working on an android app where i have different layouts for landscape and portrait I want to save some data while the orientation changes and but I find that the onSaveInstanceState is not called when the orientation is changed, I have also debugged the onDestroy() method and it is calling it but is not calling onSaveInstanceState, what is the issue is there any other way to pass during orientation change or I am doing some thing wrong?

@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
    outState.putInt("intTag", intValue);
    super.onSaveInstanceState(outState, outPersistentState);
}

this is not calling at all I have debugged it as well

You're overriding the wrong method. You need to override onSaveInstanceState(Bundle outState) .

The method you're overriding only gets called if with the attribute persistableMode is set to persistAcrossReboots in your Manifest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM