One: Life cycle of activity:
Two: created->resumed
When an application's launch icon is clicked by the user, the application starts executing from the activity's OnCreate () method. (when there are multiple activity files, the main activity file specified in the manifest file is executed).
When the OnCreate () method is executed, a quick call to the OnStart (), Onresume () method allows the user to perform related operations.
Take as little action as possible in the OnCreate () method to prevent the program from running for a long time without entering the interface.
Three: resumed->paused && paused->resumed
When another activity is started causing partial blocking (visible in the main activity section), the main activity calls the OnPause () method into the paused state. When you need to go back to the main activity, you can go back to the screen by calling the Onresume () method and perform the relevant action.
After an activity enters the paused state, it is possible for him to return to the screen, possibly into the stopped state, and then go into the destryed state to close.
When activity enters the paused state, it should stop the operation of the pause state activity in the OnPause () method, releasing the appropriate resources, and the resources the user expects to save.
When activity returns to the resumed state, the resources released in the paused state should be initialized
Four: paused->stopped && stopped->started
When activity is partially blocked into a full block (activity is not visible), the main activity calls OnStop () into the stopped state. When you go back to the main activity, the Onrestart () method is called. Then call the Onresume () method quickly.
When activity enters the stopped state, the activity object is saved in memory and the saved activity is called when the activty reverts to the resumed state. Therefore, you do not need to initialize the corresponding components.
In the OnStop () method, you want to free the unwanted resources, and in the Onrestart () method, you re-create the freed resources.
V: Destroyed:
1 activity may be a normal exit (such as clicking the Back button/using the Finish () method to exit), it is also possible to exit abnormally (stop state is not used for a long time/the foreground activity requires more resources).
When you exit normally, the relevant data is not saved, but when you exit abnormally, the relevant data is saved and the data is recovered the next time the activity instance is created.
The data stored by the system to recover the relevant data is called instance state. The instance state is stored in the Key-value pairs in the bundle object.
When the activity exits abnormally, the relevant data is saved to the object bundle via Onsaveinstancestate (). When this activity is re-created, the bundle object is passed to OnCreate () and Onrestoreinstancestate (). The data is recovered through the bundle object.
Reference: Http://hukai.me/android-training-course-in-chinese/basics/activity-lifecycle/index.html.
Android Development Learning Note (ii)-activity life cycle