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