1. Create a new activity and print out each life cycle
2, run the activity, get the following information
Oncreate--> onstart--> onresume-->
3, press CRTL+F12 switch Cheng
onsaveinstancestate--> onpause--> onstop--> ondestroy--> oncreate--> onStart--> Onrestoreinstancestate--> onresume-->
4, and then press CRTL+F12 to switch to vertical screen, found that two times the same log was printed
onsaveinstancestate--> onpause--> onstop--> ondestroy--> oncreate--> onStart--> onrestoreinstancestate--> onresume--> onsaveinstancestate--> onpause--> onStop--> onDestroy--> oncreate--> onstart--> onrestoreinstancestate--> onresume-->
5, modify the Androidmanifest.xml, add the activity android:configchanges= "orientation", perform step 3
onsaveinstancestate--> onpause--> onstop--> ondestroy--> oncreate--> onStart--> Onrestoreinstancestate--> onresume-->
6, then perform step 4, found that the same information will not be printed, but more than print a line onconfigchanged
onsaveinstancestate--> onpause--> onstop--> ondestroy--> oncreate--> onStart--> Onrestoreinstancestate--> onresume--> onconfigurationchanged-->
7, change step 5 android:configchanges= "orientation" to android:configchanges= "Orientation|keyboardhidden", perform step 3, Just print onconfigchanged
Onconfigurationchanged-->
8. Perform step 4
Onconfigurationchanged--> onconfigurationchanged-->
Summarize:
1, do not set the activity of the android:configchanges, the screen will recall the various life cycle, cut across the screen will be executed once, cut the vertical screen will be executed twice
2, set the activity android:configchanges= "orientation", the screen will recall the various life cycle, cut horizontal, vertical screen will only be executed once
3, set the activity android:configchanges= "Orientation|keyboardhidden", the screen will not recall the various life cycle, will only execute onconfigurationchanged method
Summarize the life cycle of the activity
To add, the activity's life cycle will not change when the current activity generates an event that pops up toast and alertdialog
When the activity is running, press the home key (the same as when it is fully overwritten): Onsaveinstancestate---OnPause-onStop onrestart-->onstart--->onresu Me
Activity not being completely overwritten just loses focus: onPause--->onresume
// Setting Screen Horizontal screen Baseactivity. This . Setrequestedorientation (activityinfo.screen_orientation_landscape); // Set screen vertical screen Baseactivity. this. setrequestedorientation (activityinfo.screen_orientation_portrait);
The life cycle of the activity when switching between the screen and the