Android development: Activity startup mode

1. How to set the startup mode of the Activity

You can add the launch mode of the activity in the manifest file yourself, android : launchMode="standard", if you don't write it, the system defaults to the standard mode.

2. Start mode

2.1. Default startup mode

The standard startup mode is the stack. Opening an activity will push the activity into the stack, and returning the activity will exit the stack.

 Different activities can set different startup modes

2.2. Stack top multiplexing startup mode

When the activity to be created is already on the top of the stack at this time, it will not recreate a new one.

 

Application Scenario
It is suitable for launching activities with multiple channels and multiple application calls. This setting can avoid the repeated creation of already created activities, and most of them are used through dynamic settings.

2.3. In-stack multiplexing startup mode

If the activity stack to be created already exists, all activities above the activity will be popped up, and the activity to be created will be at the top of the stack and displayed in the interface.

Application scenarios
Program main interface: We definitely don't want the main interface to be created multiple times, and it is the best effect to exit the entire App when the main interface exits.
Activities that consume system resources: For those activities that consume system resources, we can consider setting them as singleTask. mode to reduce resource consumption.

2.4. Global unique startup mode

The global unique mode means that the activity is alone in a stack. When jumping to another activity Activity2 (also the global unique mode), a separate stack will be created for Activity2, and the main activity is in the background. When calling the main activity again, it will not A new one will be created, instead waking up the main activity in the background. Only one globally unique activity can exist at a time. 

 

3. Boot logo

3.1 If you don't want to repeat the existing activities in the stack, we can also set the startup flag for the jump intent, intent.setFlags(Intent.FLAG_aCTIVITY_CLEAR_TOP)

3.2 If it is the login page of the software, when we log in successfully, we will not return to the login interface but exit directly.

To achieve this effect, we need to set the startup flag FLAG_ACTIVITY_CLEAR_TASK. After logging in, this flag will clean up all instances in the activity stack and create an activity stack for new tasks.

intent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

Guess you like

Origin blog.csdn.net/Orange_sparkle/article/details/129105190