I am trying to save data in my activity and than restore it.
I save data in on onSaveInstanceState() and then I try to restore the data in onRestoreInstanceState().
I setup breakpoint, the method onSaveInstanceState() get called. But onRestoreInstanceState() or onCreate() never did.
Here is my steps:
- start my
Activity. - press ‘Home’ button on the phone.
onSaveInstanceState()get called. - Click the icon in the launcher and launch my
Activityagain.
At this time, only onRestart() get called. But not onRestoreInstanceState() or onCreate().
Does anyone know why?
Well, if
onRestart()is called, the value of the instance variables would be maintained by the application stack itself and thus you do not need to restore them.onCreate()method is only called when yourActivity‘sonStop()is called and the process is killed.Please refer the
Activitylife cycle Android Activity Life Cycle for a clear understanding.You may want to check whether the
onStop()method is called and if your process is killed. I do no think that your process gets killed by the scenario which you have described.the
onRestoreInstanceState()method is very tricky. I do not know when exactly it is called but I saw it was called once while changing from Potrait to Landscape.