#1完整生命周期代码如下.
Package Com.wzw.lifecycle;import Android.app.activity;import Android.content.intent;import android.os.Bundle; Import Android.view.view;public class Mainactivity extends the method called when the Activity {//was created @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); System.out.println ("OnCreate");} The method that is called when it is destroyed @overrideprotected void OnDestroy () {System.out.println ("ondestory"); Super.ondestroy ();} The method called when the activity interface user is visible @overrideprotected void OnStart () {System.out.println ("OnStart"); Super.onstart ();} @Overrideprotected void Onrestart () {System.out.println ("Onrestart"); Super.onrestart ();} The method called when the activity interface user is not visible @overrideprotected void OnStop () {System.out.println ("onStop"); Super.onstop ();} The interface begins to get the method that corresponds to the focus. (The interface button can be clicked, the text box can be entered content) @Overrideprotected void Onresume () {System.out.println ("Onresume"); Super.onresume ();} The interface loses focus corresponding to the method (pause) (the button is not clickable, the text box is not input content, but the user can still see the interface) @Overrideprotected void OnPause () {System.out.println ("OnPause"); SupEr.onpause ();} public void Click (View view) {Intent Intent = new Intent (this,secondactivity.class); startactivity (Intent);}}
#2生命周期
Full life cycle oncreate--"onstart--" onresume--"onpause--" onstop--"Ondestory"
Visual life cycle onstart--"onresume--" onpause--"OnStop
Foreground life cycle onresume--"OnPause interface user is still visible, but loses focus
#3使用场景1. Application exits auto-save data ondestory OnCreate
2. Application minimized paused operation OnStop OnStart video player
3. Pause the game and start the foreground life cycle
#4TipsCalled OnCreate () when it is created----destroy call Ondestory ()
The method that is called when the activity interface user is visible onstart ()----The method that is called when the user of the activity interface is not visible onStop ()
The
interface begins to get the method that corresponds to the focus. (The interface button can be clicked, the text box can be entered content) Onresume ()----interface loses focus corresponding method (pause) (button cannot be clicked, text box is not input content, but interface user can still see OnPause ()