The start mode of the second lesson Activity

1. The startup mode of Activity

standard

Standard mode: Create a new instance every time you start Activity;

singleTop

Stack top multiplexing mode: If the new Activity is already at the top of the task stack, this Activity will not be re-created, and the current requested information is retrieved through the callback onNewIntent method.

singleTask

In-stack reuse mode: a single-instance mode;

When starting the Activity, first look for its task stack (the stack name configured by the TaskAffinity parameter):

  • If it does not exist, re-create a task stack, and then create an Activity instance and put it in;
  • If it exists, it depends on whether there is an Activity instance in the stack. If there is, it will be transferred to the top of the stack and its onNewIntent method will be called. If not, an Activity instance will be created and pushed onto the stack.

singleInstance

Single instance mode: Enhanced version of singleTask. The instance of this Activity can only be located in a single task stack.

2. The method of specifying the startup mode

AndroidMenifest configuration

<activity
    android:name="com.syy.note.firstActivity"
    android:configChanges="screenLayout"
    android:launchMode="singleTask"
    android:lable="@string/app_name" />

Intent set flag

Intent intent = new Intent();
intent.setClass(MainActivity.this,firstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Priority: Flag bit> androidmenifest configuration

Different setting range

ps: View stack information command: adb shell dumpsys activity

3. Flags of Activity

flag meaning
FLAG_ACTIVITY_NEW_TASK singleTask, multiplexing mode in the stack
FLAG_ACTIVITY_SINGLE_TOP singleTop, stack top multiplexing mode
FLAG_ACTIVITY_CLEAR_TOP When it is started, all the activities on it in the same task stack must be popped out of the stack. This flag bit generally appears together with the singleTask startup mode
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS This kind of Activity will not appear in the history Activity list

 

 

 

Guess you like

Origin blog.csdn.net/wishxiaozhu/article/details/114601294