There are four states of Activity
- Active or running state, at which time the activity runs at the front of the screen
- Paused, at which time the activity loses focus but remains visible to the user (e.g., this activity obscures a transparent or non-full-screen activity)
- Stop state, when activity is completely covered or gone
- The activity is cleared out of memory by the system at the end of the state.
The life cycle of an activity can be differentiated into a complete life cycle, a visible life cycle, and a foreground life cycle based on different criteria.
1. The process of initially calling the OnCreate () method from activity to the final call to the OnDestroy () method is called the complete life cycle. The activity will set all global states in the OnCreate () method, releasing all the resources it holds in the OnDestroy () method.
2, from the activity Call OnStart () method to start, to the corresponding OnStop () method So far this process is called the visible life cycle. At this time, the user can see the activity on the screen, although not necessarily in the foreground, and may not necessarily interact with it. Between these two methods, the user can maintain the resources that the activity needs to display. Because the corresponding method is called whenever the activity is displayed or hidden, the OnStart () method and the OnStop () method can be called multiple times throughout the life cycle.
3, starting from the activity Call Onresume () method, to call the corresponding OnPause () method, this process is called the foreground life cycle. At this time, the current activity is in front of all other activity and can be used to interact with the data.
Activity life cycle