Android Course---Save and restore user status in activity

Source: Internet
Author: User

Onsaveinstancestate  is saved after a pause and before saving is called
Onrestoreinstancestate   restore  after restart and before the display is called

 Packagecom.example.chenshuai.excise;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;/*** Created by Chenshuai on 2016/3/20.*/ Public classExcise1extendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.LAYOUT.EXCISE1); LOG.E ("Tag", "Create"); } @Overrideprotected voidOnStart () {Super. OnStart (); LOG.E ("Tag", "Start"); } @Overrideprotected voidOnresume () {Super. Onresume (); LOG.E ("Tag", "Display"); } @Overrideprotected voidOnPause () {Super. OnPause (); LOG.E ("Tag", "Pause"); } @Overrideprotected voidOnStop () {Super. OnStop (); LOG.E ("Tag", "Stop"); } @Overrideprotected voidOnrestart () {Super. Onrestart (); LOG.E ("Tag", "Reboot"); } @Overrideprotected voidOnDestroy () {Super. OnDestroy (); LOG.E ("Tag", "Destroy"); }    //Save and restore User state    inti = 0; @Overrideprotected voidonsaveinstancestate (Bundle outstate) {Super. Onsaveinstancestate (outstate); I++; LOG.E ("Tag", "Save user's State" +i); //store data in a put method, stored as a key-value pairOutstate.putint ("Key", i); }    //restore a user's previously saved state@Overrideprotected voidonrestoreinstancestate (Bundle savedinstancestate) {Super. Onrestoreinstancestate (savedinstancestate); inti = Savedinstancestate.getint ("Key"); LOG.E ("Tag", "Get user saved state before" +i); }

Android Course---Save and restore user status in activity

Related Article

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.