The first line of code: Android Guo Lin The stack for the activity is a last-in first-out structure. Activity status
- Operating State (S1):
- The activity is in the state of interaction with the user, which is the activity at the top of the stack.
- The system generally does not consider reclaiming the memory at that place.
- Paused state (S2):
- Activity is no longer at the top of the stack (another activity comes in frontof the activity), but is still visible.
- The system considers reclaiming memory only when the memory is very low .
- Stop State (S3):
- Activity is not at the top of the stack & is completely invisible (theactivity is no longervisible).
- The system saves the activity's corresponding state and variable, but the chance of memory being recycled increases, that is, there is no guarantee that the activity will not be recycled. (Process is killed)
- Destroy state (S4):
- Activity is removed from the stack (call finish () or click the back key).
- Focus on recovering the memory occupied by activity in this state.
Activity lifetimes
- OnCreate ()
- When activity is created, it is called to complete various initialization operations.
- OnStart ()
- The activity is called when it becomes visible (invisible) by invisible (invisible).
- Onresume ()
- When the activity is ready to be called when interacting with the user, the activity must be at the top of the stack (S1).
- OnPause ()
- Other activity is called (no longer on top of the stack), and key data is saved but still visible (visible, S2).
- OnStop ()
- Called when activity becomes invisible (invisible) (S3).
- OnDestroy ()
- Called before activity is destroyed (S4).
- Onrestart ()
- The activity is called (s3→s1, invisible → visible) before it is changed from the stop state to the running state.
- Because the memory of the activity may have been reclaimed since onstop (), it is necessary to call Onrestart () before calling OnStart () becomes visible.
Add
- Other than Onrestart (), the remaining lifetime is one by one correspondence
- OnCreate () vs OnDestroy ()
- OnStart () vs OnStop ()
- Onresume vs OnPause ()
First line of code: Android Learning Note: Activity life cycle