Start: Trigger OnCreate () OnStart () Onresume ()
Home key: Trigger OnPause () OnStop ()
Back key exit: Trigger OnPause () OnStop () OnDestroy ()
The home key exits and goes in: Trigger Onrestart () OnStart () Onresume ()
Start:
Home key:
Re-entry:
Exit:
Source:
Packagecom. Treedream.life;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.view.Menu;ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {PrivateTextView TextView; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); System.out.println ("OnCreate"); TextView=(TextView) Findviewbyid (R.ID.TEXTVIEW1); Textview.settext ("OnCreate"); } @Overrideprotected voidOnStart () {Super. OnStart (); System.out.println ("OnStart"); } @Overrideprotected voidOnresume () {Super. Onresume (); System.out.println ("Onresume"); } @Overrideprotected voidOnPause () {Super. OnPause (); System.out.println ("OnPause"); } @Overrideprotected voidOnStop () {Super. OnStop (); System.out.println ("OnStop"); } @Overrideprotected voidOnDestroy () {Super. OnDestroy (); System.out.println ("OnDestroy"); } @Overrideprotected voidOnrestart () {Super. Onrestart (); System.out.println ("Onrestart"); TextView=(TextView) Findviewbyid (R.ID.TEXTVIEW1); Textview.settext ("Onrestart"); } }
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity " > <TextViewAndroid:id= "@+id/textview2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/tree" /> <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignleft= "@+id/textview2"Android:layout_below= "@+id/textview2"Android:layout_margintop= "40DP"Android:text="" /> <TextViewAndroid:id= "@+id/textview3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignleft= "@+id/textview1"Android:layout_below= "@+id/textview1"Android:layout_margintop= "20DP"Android:text= "Life gives us a huge and infinite noble gift, this is youth: full of strength, full of anticipation, full of desire for knowledge and struggle, full of hope and confidence and youth." " /> <ImageViewAndroid:id= "@+id/imageview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_centerhorizontal= "true"Android:layout_marginbottom= "44DP"android:src= "@drawable/x" /></Relativelayout>
Activity_main.xml
<?XML version= "1.0" encoding= "Utf-8"?><Resources> <stringname= "App_name">Life</string> <stringname= "Action_settings">Settings</string> <stringname= "Hello_world">Hello world!</string> <stringname= "Tree">Treedream Android</string></Resources>
String.xml
Android--activity life cycle