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