Save recovery temporary letter-android using onsaveinstancestate and Onrestoreinstancestate

Source: Internet
Author: User

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

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.