[Android] Four startup modes of Activity

Android's management of activities is achieved through the stack.
There are four specific implementation modes for stacking and popping each time an Activity is created or destroyed:

1. Standard (no explicit designation, this mode is the default)

Every time a new Activity is started, it will be directly pushed onto the stack and at the top of the stack, regardless of whether the Activity is already in the stack.

Two, singleTop: stack top multiplexing mode

When starting the Activity, check whether the activity is already at the top of the stack, if it is, use the Activity directly, otherwise, create a new Activity to the stack.

Three, singleTask: singleton mode in the stack

When starting the Activity, check whether the activity already exists in the stack; if it exists, pop all the activities above the Activity in the stack directly, and put the Activity on the top of the stack, otherwise, create a new Activity and push it onto the stack.

Four, singleInstance: single instance mode in the heap

The singleInstance startup mode is the most special and complex of the four modes. Its biggest feature is: it allows our application and other programs to share this Activity instance

The activation of the Activity specified as the singleInstance startup mode will enable a new stack to manage the activity. No matter which application accesses the Activity, it will access the same stack, thus solving the problem of sharing activity instances.

Guess you like

Origin blog.csdn.net/weixin_40849588/article/details/90142632