You rewrite the activity of several life cycle methods, run to know what is going on, really lazy people can see: Click to open the link.
OnCreate: Executes when the activity is created and executes only once.
OnStart: Executes when the interface is visible.
Onresume: The interface gets the focus, and the button executes when it is clicked.
OnPause: The interface loses focus and the button does not click.
OnStop: Performed when the interface is not visible.
OnDestroy: Destroy, execute only once.
Onrestart: Occurs before the interface, is not destroyed, the invisible state returns to the visible state, executes the Onrestart and executes the OnStart
Usage scenarios:
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
The screen has an impact on the activity life cycle!!
Vertical screen switch to horizontal screen will be destroyed in the creation, if you do not do processing, then the data will be lost!
Horizontal screen switch to vertical screen will have two life cycle, the middle will be destroyed, the data will be lost.
Solution: Add the phrase red:
<activity android:name= ". Mainactivity "android:label=" @string/app_name " android:configchanges="orientation| Keyboardhidden|screensize">
Orientation: Eliminate the influence of the screen.
Keyboardhidden: Eliminating keyboard effects
ScreenSize: Eliminate screen size change effect, this property can not be set before 4.0, 4.0 and above must be set.
Android activity life cycle and screen shift problem