Activity mainly has the following seven callback methods:
1, OnCreate ()
Called when the activity is first created.
2, OnStart ()
Called when the activity becomes visible from invisible.
3, Onresume ()
Called after the activity is ready, the activity must be at the top of the stack at the back of the stack, and is in a running state.
4, OnPause ()
When you are ready to start or restore another activity, you can release the CPU-consuming resources in this method, save some important data, this method executes fast, and cannot affect the use of the new stack top activity.
5, OnStop ()
Called when the activity is completely invisible, the difference from the OnPause () method is that if the new activity that starts is a dialog box, the OnPause () method is executed and the OnStop () method is not executed.
6, OnDestroy ()
Called before the activity is destroyed
7, Onrestart ()
Called before activity is stopped into a running state (when activity is restarted)
The above seven methods except the Onrestart () method, the other is 22 relative, so that the activity can be divided into three
Survival period.
1. Full lifetime
The activity between the OnCreate () method and the OnDestroy () method is the complete survival period. General situation
, an activity completes various initialization operations in the OnCreate () method, while the OnDestroy () method finishes
into a free memory operation.
2. Visible lifetime
The activity that is experienced between the OnStart () method and the OnStop () method is the visible lifetime. In the visible survival
Period, activities are always visible to the user, even though they may not be able to interact with the user. We can pass these two
Methods to manage resources that are visible to the user in a reasonable way. For example, to load a resource in the OnStart () method,
The resource is freed in the OnStop () method to ensure that activities that are in a stopped state do not consume too much memory.
3. Foreground lifetime
The activity between the Onresume () method and the OnPause () method is the foreground lifetime. At the front desk
During the lifetime, the activity is always in the running state, at this time the activity is can and the user mutual, we usually
See and touch most of the activities in this State as well.
Content reference to: "First line of code Android"
Android Life cycle