Activity is a component that provides users with an interactive interface. This interface is usually full screen, but it can also be a small window floating above other windows.
An android application is usually composed of multiple loosely coupled activities. Generally, there is a "Main" activity, which is displayed when the user starts the program for the first time.
Now in front of the user. The program then starts other activities based on the user's operations. When a new activity is started, the previous activity "stopped"
(But it does not have to be destroyed). The system saves it in "Back stack", and the newly started activity is placed in "back
Stack, and display it at the front of the screen. After the user completes the interaction with the activity at the beginning of the stack, the activity at the beginning of the stack is removed from the stack by clicking the back key.
Pop and destroy the previous activity resumes.
2. Activities lifestyle
ResumedThe activity is at the front of the screen and obtains the user's focus.PausedThis activity is partially visible, but the user focus is on another activity floating above this activity window.StoppedThis activity is invisible, and of course there is no user focus.
Note: When the program is in the paused and stopped States, if the system memory is low, the system will kill the process to save memory. Callback Function of the activity (the function starting with "on" in the activity ):
Visible:Onresume () and onpause () are a pair. They are called when the activity gets the user focus.
Onrestart (), onstart (), and onstop () belong to a ring, which is called based on whether the activity is visible or not.
When the program is in the paused and stopped status (that is, after the callback function onstop () or onpause () is called), if the system memory is low, the system will destroy this activity to save memory.
Table 1.A summary of the activity lifecycle's
|Method||Description||Can I be killed after being called?||Next|
|Oncreate ()||It is called when an activity is created for the first time or when its memory is captured and then used by users. You can pass a bundle parameter to this method, which contains the previous status of the activity.||No||Onstart ()|
|Onrestart ()||It is called when the previous status is stopped and the current status is visible.||No||Onstart ()|
Called when the activity is visible.
Why is the next called function onstop ()??
This API is called when an activity wants to obtain the user focus.
|Onpause ()||It is called when the system needs to resuming another activity (that is, when it loses focus ).
It is best to save some variable data in this method.
|Onstop ()||Called when activity becomes invisible.||Yes||Onrestart ()
|Ondestroy ()||Called when the activity changes to destoried.
When the finish () method is called or the system temporarily destroys the instance of this activity to save memory space, this callback method is called.
You can use isfinishing () to differentiate the two cases.