Example code:
public class Mainactivity extends Actionbaractivity {private static final String TAG = "mainactivity"; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); if (null! = savedinstancestate) {int inttype = Savedinstancestate.getint ("Inttype"); String StringType = savedinstancestate.getstring ("StringType"); } setcontentview (R.layout.activity_main); LOG.I (TAG, "onCreate----performed--------"); } @Override protected void Onrestoreinstancestate (Bundle savedinstancestate) {super.onrestoreinstancestate (s Avedinstancestate); int inttype = Savedinstancestate.getint ("Inttype"); String StringType = savedinstancestate.getstring ("StringType"); LOG.I (TAG, "onrestoreinstancestate----performed--------"); } @Override protected void Onsaveinstancestate (Bundle outstate) {super.onsaveinstancestate (outstate); Outstate.putint ("Inttype", 0); Outstate.putstring ("StrinGType "," saved "); LOG.I (TAG, "onsaveinstancestate----performed--------"); }}
When will the Onsaveinstancestate method be executed?
1. When the user presses the home key.
It is obvious that the system does not know how many other programs you want to run after you press home, and it is not known whether acitvity a will be destroyed so the system will call Onsaveinstancestate, giving the user the opportunity to save some non-permanent data, following several analyses that follow this principle.
2. Press and hold the home key to select another program to run.
3. Press the Power key (turn off the screen display).
4. When a new activity is initiated from activity a.
5. When the screen orientation is switched.
When will the Onrestoreinstancestate method be executed?
Activity a "really" is destroyed by the system, and if only stay in the case of this possibility, then the method will not be called, for example, when the Acitivty A is being displayed, the user presses the home button back to the main interface, and then the user next to return to activity a, In this case, activity A is not normally destroyed by the system for memory reasons, so activity A's Onrestoreinstancestate method will not be executed.
The function of saveinstancestate parameter in OnCreate method