Saving Activity state in Android

Source: Internet
Author: User

 This :

@Override Public voidonsaveinstancestate (Bundle savedinstancestate) {Super. Onsaveinstancestate (savedinstancestate); //Save UI state changes to the savedinstancestate. //This bundle would be passed to onCreate if the process is//killed and restarted.Savedinstancestate.putboolean ("Myboolean",true); Savedinstancestate.putdouble ("MyDouble", 1.9); Savedinstancestate.putint ("MyInt", 1); Savedinstancestate.putstring ("MyString", "Welcome Back to Android"); //etc.}
The Bundle is essentially a storing a NVP ("Name-value Pair") map, and it'll get passed in to OnCreate and also onrestoreinstancestate where you ' d extract the Valu Es like this:@Override Public voidonrestoreinstancestate (Bundle savedinstancestate) {Super. Onrestoreinstancestate (savedinstancestate); //The Restore UI state is from the savedinstancestate. //This bundle had also been passed to OnCreate. BooleanMyboolean = Savedinstancestate.getboolean ("Myboolean"); DoubleMyDouble = savedinstancestate.getdouble ("MyDouble"); intMyInt = Savedinstancestate.getint ("MyInt"); String myString= Savedinstancestate.getstring ("MyString");} you do usually use ThisTechnique to store instance values forYour application (selections, unsaved text, etc.).

Original: Http://stackoverflow.com/questions/151777/saving-activity-state-in-android

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.