Four Ways for Android to Start activity and Open the Pit of activity in Other Applications

  • 2021-07-10 20:56:26
  • OfStack

The four modes of starting Android are standard, singleTop, singleTask and singleInstence.

standard is the most common activity startup mode, and it is also the default startup mode. When starting an activity, it will enter the top of the return stack. The system does not care whether there is the same activity in the stack, in a last-in-first-out manner.

singleTop means that when the activity is started, the system first determines whether there is the same activity at the top of the stack, and if there is no new activity, otherwise it will not create a new activity. But use him directly.

In singleTask mode, when the activity is started, the system first determines whether there is an instance of the activity in the stack. If there is no new instance, if there is, the stack above the existing activity will be out of the stack.

singleInstance mode will create a new stack when starting. When other programs access this activity and start this activity, they get this instance, and all applications access the same instance.

When the experimental application B accesses the active A with singleInstance startup mode, attention should be paid to adding it to AndroidManifest. xml of A application


 <activity
  android:name="com.example.testandroid.BActivity"
  android:exported="true" ></activity> 

android: exported= "true" This is a statement that the activity can be opened by other applications


Related articles: