I. Life cycle of activity
1, OnCreate (): Called when the activity is first created, to complete the initialization of the activity, such as loading layout, binding events, etc.
2. OnStart (): Called when an activity becomes visible from invisible
3. Onresume (): Called when the activity is ready and the user interacts. The activity must be at the top of the stack at the back of the stack and is in a running state
4. OnPause (): Called when the system is ready to start or resume another activity. In this method, some CPU-consuming resources are freed, and some key data is saved, but this method must be fast, otherwise it will affect the use of the new stack top activity.
5, OnStop (): Called when the activity is completely unavailable. The difference between OnPause () is that if you start a dialog-style activity, the OnPause () method executes, and OnStop () does not perform
6, OnDestroy (): Called before the activity is destroyed, and then the state of the activity becomes the destroyed state
7, Onrestart (): Called before the activity is changed from the stop state to the running state, that is, the activity is restarted
The diagram is as follows:
Second, the activity of the start mode
1, Standard mode: In standard mode, whenever a new activity is started, it will be in the stack in the return stack, and at the top of the stack position. For activities that use standard mode, the system does not care if the activity is already present in the return stack, and an instance of the activity is created each time it is started.
2. Singletop mode: If it is found that the stack top of the return stack is already active at startup, it is considered that it can be used directly and no new activity instances will be created. However, when the activity is not at the top of the stack, it is started again, and a new instance is created.
3, Singletask mode: Each time the activity is started, the system will first check the return stack for the existence of the activity instance, if found already exist then directly use the instance, and put all activities on top of the activity out of the stack, if not found will create a new activity instance
4. SingleInstance mode (singleton mode): The activity of this mode will enable a new return stack to manage this activity (if the Singletask mode specifies a different taskaffinity, a new return stack will also be started). In this mode there will be a separate return stack to manage this activity, regardless of which application accesses the activity, the same return stack is shared, and the problem of shared activity instances is resolved.
Native Android (ii)--Understanding activity