Detailed introduction to four startup modes of activity

Detailed introduction to four startup modes of activity

In Android, each interface is an activity, and the interface switching operation is actually an instantiation operation between multiple different activities. In Android, the startup mode of activity determines the startup and operation mode of activity.

There are four startup modes for Android activities:

Four startup modes of activity:

. standard

Mode starts the mode. Each time an activity is activated, it will create an activity and put it into the task stack.

. singleTop

If an instance of the activity happens to exist at the top of the task stack, the instance will be reused. Otherwise, a new instance will be created and placed at the top of the stack (even if the activity instance already exists in the stack, it will be created as long as it is not at the top of the stack).

. singleTask

If there is already an instance of the activity in the stack, the instance will be reused (onnewintent() of the instance will be called). When reused, the instance will return to the top of the stack, so the instance above it will be removed from the stack. If the instance does not exist on the stack, a new instance will be created and placed on the stack.

. singleInstance

Create the activity instance in a new stack and let multiple applications share the activity instance in the stack. Once the instance of the activity to change the mode exists in a stack, any application will reuse the instance in the stack when activating the activity to change the mode. The effect is equivalent to that multiple applications share an application. Whoever activates the activity will enter the same application.

Note: when the fourth startup mode is used, the release sequence of activities is different when clicking the return key. For example, if firstactivity is set to singleinstance, the sequence of starting activities is main - > first - > main - > first - > main, there will be the following two activity stacks:

When you click the return key, the release order of activities is as follows: first release the three mainactivities in task 1, and then release the firstactivity in task 2.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>