Methods to execute when destroying and rebuilding data

Source: Internet
Author: User

Onsaveinstancestate () and Onrestoreinstancestate ()

  • Full life cycle of activity
    onCreate()–> onStart() –> onRestoreInstanceState() –> onResume() –> onSaveInstanceState() –> onPause() –> onStop() –>onDestroy()

  • The two methods of onsaveinstancestate and Onrestoreinstancestate are known to be Activity the preservation of data for destruction and reconstruction.

  • Press the back key or call the finish () method to actively destroy the activity , this time the system will think that we no longer need it, the Activity system will not execute Onsaveinstancestate .
  • Press the home key to direct the program backstage, this time the system will execute onsaveinstancestate () The system knows that you do not need this activity just backstage.
    At this point we wake up the application and do not execute the onrestoreinstancestate method, because we do not destroy the rebuild after we wake up in the background Activity , so we do not call Onrestoreinstancestate .
  • Press the home key will execute onsaveinstancestate , and then the system because of insufficient memory to kill the process, this time the system feel that they do wrong, to give you a state of recovery, when we start the program again will be executed Onrestoreinstancestate This method to restore data to us.
  • In the default Activity , if the system will be destroyed and re-created when the screen is switched Activity , the system will execute onsaveinstancestate and onrestoreinstancestate , because this is the system to be Activity destroyed, the system is responsible for executing these two methods to give you to save and restore data.

Methods to execute when destroying and rebuilding data

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.