Transferred from: http://blog.chinaunix.net/uid-22985736-id-2977672.html
Onsaveinstancestate () and onrestoreinstancestate () are not part of the activity lifecycle and are invoked only when an activity is accidentally destroyed, such as low memory, The home button is pressed (note: Pressing the back key is the active destruction of an activity, which will not be called). You can also use these two methods to stage some data when you need to change the orientation of the screen.
The following example of Baidu Map application, the use of these two methods, used to save and restore the map view.
@Override
protected void Onsaveinstancestate (Bundle outstate) {
CPoint = Mapview.getmapcenter (); Gets the center point of the current Mapview.
Outstate.putint ("Lat", cpoint.getlatitudee6 ()); Temporary presence in Outstate
Outstate.putint ("Lon", Cpoint.getlongitudee6 ());
Super.onsaveinstancestate (outstate);
}
@Override
protected void Onrestoreinstancestate (Bundle savedinstancestate) {
int lat = savedinstancestate.getint ("lat"); Recovering from saved data
int lon = Savedinstancestate.getint ("Lon");
CPoint = new GeoPoint (lat, lon);
Super.onrestoreinstancestate (savedinstancestate);
}
Android Onsaveinstancestate () and its pairing method.