The role of 1.Activity
Activity is the interface between the user and the Android program. An activity is the equivalent of a window in which various controls can be placed to interact with the user. Windows are usually filled with screens, but can also be smaller than the screen and float on top of other windows. Functionality is similar to a controller in MVC design mode, but it is not a user interface in itself.
The 2.Activity life cycle consists of the following 7 methods
Created: OnCreate ()
Start: OnStart ()
Recovery: Onresume ()
Pause: OnPause ()
Stop: OnStop ()
Destroyed: OnDestroy ()
Restart: Onrestart ()
This is just literally the meaning of English, in the application the method is actually 22 correspondence:
OnCreate () and OnDestroy (): Can be understood as creating application windows and destroying Windows
OnStart () and OnStop (): Can be understood as visible and invisible to the program window
Onresume () and OnPause (): It can be understood that the program window gets focus (or edit) and loses focus
Onrestart (): After the activity has been onstop, but not OnDestroy, when the activity is started again call Onrestart (and no longer call OnCreate) method;
OnDestroy, the OnCreate method is called.
3.Activity Boot Order
Start order of the first activity: OnCreate (), OnStart (), Onresume ()
Start order of the second activity: the first activity OnPause () The second activity onCreate (), OnStart (), Onresume (), and OnStop ()
Return to the first activity boot order: The second Activity onPause (), the first activity Onrestart (), OnStart (), Onresume (), Second Activity onStop ()
OnDestroy ()
In addition, the activity in the OnPause, OnStop, OnDestroy state, the system can destroy the activity of the process, so we are processing the data to be saved,
It is best to onpause methods because the OnStop and OnDestroy methods are not necessarily called.
Activity of Android four components