Briefly introduce the four startup modes of Activity in Android

  • 2021-06-28 14:08:04
  • OfStack

Each interface in Android is an Activity, and switching interface operations are actually instantiated operations between different Activitys.The startup mode of Activity in Android determines how Activity is started.

Activity has four startup modes:

1. standard, the default startup mode, creates a new instance and puts it in the task stack whenever Activity is activated, so there may be more than one instance of Activity in the task stack at the same time.

2. singleTop, when Activity is activated, if this Activity is at the top of the stack, no new instance will be created;If the top of the stack is not this Activity, a new instance is created.

3. singleTask, if there is an instance of Activity in the stack, remove other instances of Activity above that instance in the stack so that the instance of Activity is at the top of the stack;If no instance exists in the stack, a new instance is created.

4. singleInstance, an instance of Activity shared by multiple applications, is reused whenever the Activity is activated, regardless of whether it is the same application or not.

You can set the startup mode for Activity in AndroidManifest.xml by setting the android:launchMode property.

Some applications need to jump back and forth between two forms, such as A-- > B, B-- > A,..., you need to set the start mode of A and B to singleTask, otherwise you will jump back and forth in both forms when you press the return key.

The above is the four startup modes of Activity in Android introduced to you by this site. I hope it will be helpful to you!


Related articles: