Saving an activity state
satya - Wednesday, May 19, 2010 11:10:34 PM
onsaveinstancestate
onsaveinstancestate
Search Google for: onsaveinstancestate
Search Android Developers Group for: onsaveinstancestate
Search Android Beginers Group for: onsaveinstancestate
satya - Wednesday, May 19, 2010 11:10:53 PM
onrestoreinstancestate
onrestoreinstancestate
Search Google for: onrestoreinstancestate
Search Android Developers Group for: onrestoreinstancestate
Search Android Beginers Group for: onrestoreinstancestate
satya - Tuesday, June 22, 2010 11:31:18 PM
From the sdk docs
When the system, rather than the user, shuts down an activity to conserve memory, the user may expect to return to the activity and find it in its previous state.
To capture that state before the activity is killed, you can implement an onSaveInstanceState() method for the activity. Android calls this method before making the activity vulnerable to being destroyed ? that is, before onPause() is called. It passes the method a Bundle object where you can record the dynamic state of the activity as name-value pairs. When the activity is again started, the Bundle is passed both to onCreate() and to a method that's called after onStart(), onRestoreInstanceState(), so that either or both of them can recreate the captured state.
Unlike onPause() and the other methods discussed earlier, onSaveInstanceState() and onRestoreInstanceState() are not lifecycle methods. They are not always called. For example, Android calls onSaveInstanceState() 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. Use onPause() for that purpose instead.