There is a method named OnCreate in the activity. This method is called by the system when activity is created, and is the beginning of an activity life cycle.
Parameters of the OnCreate method savedinstancestate
The complete definition of the OnCreate method is as follows: public void OnCreate (bundle savedinstancestate) {----------------The parameters of the OnCreate method are parameters of a Bundle type. Super.oncreate (savedinstancestate);} Data of bundle type is similar to data of map type, Is the literal understanding that stores data in the form of Key-value Savedinstancestate is the state data in Savedinstancestate that holds the state of the activity, from the Onsaveinstancestate method is used to preserve activity. of the state. Activity will call this method to save the state before the end of the life cycle. This method has a parameter name that is the same as the OnCreate method parameter name. as follows: public void Onsaveinstancestate (Bundle savedinstancestate) {super.onsaveinstancestate (savedinsancestate);} When an activity is completed, if you need to save the state, in Onsaveinstancestate, the state data is placed in the form of Key-value into Savedinstancestate. Thus, when an activity is created, the state data can be obtained from the OnCreate parameter savedinsancestate. State this parameter in the implementation of the application has a great use, such as: A game before exiting, save the current game running state, when the next time you open the last time to continue to play. Another example: E-book programs, when a novel is read to the 199th page after the exit (whether it is not enough memory or the user automatically close the program), the next time you open, the reader may have forgotten the last time you read the page, but the reader would like to continue the last reading. If the saveinstallstate parameter is used, it is easy to solve the above problem.
Android Java Grammar Learning