I am refering to http://developer.android.com/reference/android/app/Activity.html.
I have an activity which can be \"interrupted\" by the user, e.g. the user opens
Have a look at the Application Fundamentals, specifically this part:
Unlike
onPause()
and the other methods discussed earlier,onSaveInstanceState()
andonRestoreInstanceState()
are not lifecycle methods. They are not always called. For example, Android callsonSaveInstanceState()
before the activity becomes vulnerable to being destroyed by the system, but does not bother calling it when the instance is actually being destroyed by a user action (such as pressing the BACK key). In that case, the user won't expect to return to the activity, so there's no reason to save its state.Because
onSaveInstanceState()
is not always called, you should use it only to record the transient state of the activity, not to store persistent data. UseonPause()
for that purpose instead.
Basically, any persistant data should be written out in your onPause()
method and read back in onResume()
. Check out the Data Storage article for ways of saving data.