Android Java Grammar Learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.