Onsaveinstancestate and onrestoreinstancestate

Source: Internet
Author: User
Public class mainactivity extends activity {Private Static final string tag = "mainactivity"; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); If (savedinstancestate! = NULL) {log. E (TAG, "oncreate | Reade page ----" + savedinstancestate. getstring ("page");} system. out. println ("11111") ;}@ override public Boolean oncreateoptionsmenu (menu) {getmenuinflater (). inflate (R. menu. activity_main, menu); Return true;}/*** this method is called only when the acitivity is recycled by the system, this is an opportunity for users to save data. Of course, you can also not save it. * if you think that you press the back key to destroy the current acitivity, The onsaveinstancestate method will not be executed. ** about this possibility: * 1 Press the power key * 2 to jump to another activity * 3 press home or long press home to select another application * 4 to switch between portrait screens **. However, we do not save the data in this method because it is stopped from setting. application this method will not be executed * generally saves data in the onstop method of the life cycle */@ override protected void onsaveinstancestate (bundle outstate) {// todo auto-generated method stub log. E (TAG, "onsaveinstancestate run .. "); outstate. putcharsequence ("page", "page 8"); super. onsaveinstancestate (outstate);}/*** onrestoreinstancestate is called only when the activity is indeed recycled by the system, for example, switching the onrestoreinstancestate on the horizontal and vertical screens will be executed * generally press the Home Key to return to the activity. acitivity is generally not destroyed by the system, and onrestoreinstancestate will not be called * onrestoreinstancestate) the parameter is also passed to oncreate (bundle savedinstancestate) **/@ override protected void onrestoreinstancestate (bundle savedinstancestate) {// todo auto-generated method stub log. E (TAG, "onrestoreinstancestate run .. "); log. E (TAG, "onrestoreinstancestate | Reade page ----" + savedinstancestate. getstring ("page"); super. onrestoreinstancestate (savedinstancestate );}}

 

 

 

 

05-04 12:39:24. 129: E/mainactivity (13121): onsaveinstancestate run ..
05-04 12:39:24. 539: E/mainactivity (13121): oncreate | Reade page ---- page 8
05-04 12:39:24. 539: E/mainactivity (13121): onrestoreinstancestate run ..
05-04 12:39:24. 539: E/mainactivity (13121): onrestoreinstancestate | Reade page ---- page 8
05-04 12:40:22. 919: E/mainactivity (13121): onsaveinstancestate run ..
05-04 12:40:28. 379: E/mainactivity (13121): oncreate | Reade page ---- page 8
05-04 12:40:28. 379: E/mainactivity (13121): onrestoreinstancestate run ..
05-04 12:40:28. 379: E/mainactivity (13121): onrestoreinstancestate | Reade page ---- page 8
05-04 12:39:24. 129: E/mainactivity (13121): onsaveinstancestate run ..
05-04 12:39:24. 539: E/mainactivity (13121): oncreate | Reade page ---- page 8
05-04 12:39:24. 539: E/mainactivity (13121): onrestoreinstancestate run ..
05-04 12:39:24. 539: E/mainactivity (13121): onrestoreinstancestate | Reade page ---- page 8
05-04 12:40:22. 919: E/mainactivity (13121): onsaveinstancestate run ..
05-04 12:40:28. 379: E/mainactivity (13121): oncreate | Reade page ---- page 8
05-04 12:40:28. 379: E/mainactivity (13121): onrestoreinstancestate run ..
05-04 12:40:28. 379: E/mainactivity (13121): onrestoreinstancestate | Reade page ---- page 8

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.