In activity, there are two methods for temporarily saving and recovering state information, both of which are:
- public void Onsaveinstancestate (Bundle savedinstancestate);
- public void Onrestoreinstancestate (Bundle savedinstancestate);
The description of these two methods is not what this article describes, please refer to the developer website! :)
The following scenarios call Onsaveinstancestate, respectively:
- The user presses the home button;
- Press and hold the home button and choose to run other programs;
- Press the power button;
- Screen orientation switch (possible);
- Start a new activity, etc.;
Suitable for temporary information: Do not use this Save method when you want to save persistent information! As a simple example, when we click on Home, the Onsaveinstancestate method will be called, at this time, if you terminate the program from the settings, then back to find that the saved data does not exist.
Save recovery temporary letter-android using onsaveinstancestate and Onrestoreinstancestate