I have a couple of question regarding onRestoreInstanceState
and onSaveInstanceState
.
1) where do these methods fit the activity lifecycle
1) where do these methods fit the activity lifecycle?
from the developer docs.
onSaveInstanceState (Bundle outState)
This method is called before an activity may be killed so that when it comes back some time in the future it can restore its state. For example, if activity B is launched in front of activity A, and at some point activity A is killed to reclaim resources, activity A will have a chance to save the current state of its user interface via this method so that when the user returns to activity A, the state of the user interface can be restored via onCreate(Bundle) or onRestoreInstanceState(Bundle).
The default implementation of onSaveInstanceState() takes care of saving the data related with each n every view that is having an id.
If called, this method will occur before onStop(). There are no guarantees about whether it will occur before or after onPause().
onRestoreInstanceState (Bundle savedInstanceState)
This method is called after onStart() when the activity is being re-initialized from a previously saved state
3) is onRestoreInstanceState called when the activity is destroyed? what does this mean? an activity always destroyed except for scenarios when another activity is floating on top of current.
This method is called after onStart() when the activity is being re-initialized from a previously saved state, given here in savedInstanceState (which is a bundle object containing data saved in onSaveInstanceState(Bundle)).
Most implementations will simply use onCreate(Bundle) to restore their state, but it is sometimes convenient to do it here after all of the initialization has been done or to allow subclasses to decide whether to use your default implementation. The default implementation of this method performs a restore of any view state that had previously been frozen by onSaveInstanceState(Bundle).
4) onRestoreInstanceState appears to be called only from instrumentation in jelly bean. Is this no longer relevant to activity lifecycle?
No. onRestoreInstanceState has been there since API level 1. And its still part of the new Jelly Bean API.