Android Learning record life cycle Introduction and Page jump

Source: Internet
Author: User

Activity life cycle (7 methods and 3 stages)

7 methods:

Void onCreate (Bundle savedlnstancestate)

Void OnStart ()//Start

Void Onrestart ()//Reset

Void Onresume ()//reply

Void onPause ()//Pause

Void onStop ()//Stop

Void OnDestroy ()//Destroy

3 stages:

The activity is started at this stage by performing 3 life cycles, namely OnCreate, OnStart, and Onresume methods.

Acticity regain focus: If the activity program gets the focus, it will perform 3 cycles, respectively, OnCreate, OnStart, and Onresume methods.

Close activity: When activity is closed, the system executes 3 life cycle methods, namely OnPause, OnStop, and OnDestroy.

From the life cycle of the activity above, it is not difficult to see that there are two layers of loops, the first loop is onpause→onresume→onpause (Focus life cycle)

The second loop is onstart→onrestart→onresume→onpause→onstop (life cycle)

The first layer loops around the activity focus and loses, and in the loop the activity is always visible, and the second loop is the activity visible and not

Visible in the process of looping.

The specific life cycle of the activity is as follows:

The whole life cycle: oncreate→ ... →ondestory

Visual life cycle: onstart→ ... →onstop

Focus Life cycle: Onresume→onpause

To store information in the form of a stack.

 Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.main); Button Btnbutton= (Button) Findviewbyid (R.id.btnstart);//Get Btnstart Components//Btnstart is the name of the buttonBtnbutton.setonclicklistener (listener);//setting listener events for Btnstart    }    PrivateOnclicklistener listener=NewOnclicklistener () {//To create a listener event object@Override Public voidOnClick (View v) {//TODO auto-generated Method StubIntent intent=NewIntent ();//Create a Intent object//set the activity to open for intentIntent.setclass (mainactivity. This, Testactivity.class); StartActivity (intent);//start activity with intent//mainactivity is the main page name, Testactivity is the second page name        }    }

Android Learning record life cycle Introduction and Page jump

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.