Android Activity State Save

Source: Internet
Author: User

One, interrupted by other tasks (to call), open again want to keep the data

    PrivateString Save_instance_tag = "Atwal"; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_cal); if(Savedinstancestate! =NULL) {String s=savedinstancestate.getstring (Save_instance_tag); }    }    //The system is called before the current activity is reclaimed, and back & Home does not call this method@Override Public voidonsaveinstancestate (Bundle outstate, Persistablebundle outpersistentstate) {if(Outstate! =NULL) {outstate.putstring (Save_instance_tag,"Hello Atwal"); }        Super. Onsaveinstancestate (Outstate, outpersistentstate); }

Second, I hope the screen switch, press the home or back key and then return to retain data

    @Override    protectedvoid  Onresume () {        super. Onresume ();         this. getpreferences (mode_private). getString (Save_instance_tag, "");    }    @Override    protectedvoid  onPause () {        super. OnPause ();         this. getpreferences (mode_private). Edit (). putstring (Save_instance_tag, "after pause");    

Android activity status Save

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.