The startup mode of the activity

1. Activity's lanchMode

     standard: Standard mode, each time a new Activity instance is started. Whoever starts the Activity runs in the stack where the Activity that started it is located. For example, if Activity A starts Activity B, then B will be in the stack where A is located. So using ApplicationContext (non-Activity similar Context) to start standard mode Activity will report the following error:

      The reason is that ApplicationContext does not have a task stack, so when starting an Activity, you need to specify the FLAG_ACTIVITY_NEW_TASK flag bit, which has actually been started in singleTask mode.

    singleTop: If the Activity is at the top of the task stack, the Activity will not be created, and the Activity's onNewIntent method will be called.

    singleTask: The task stack that the Activity wants exists, and there is an instance of the Activity in the stack (the Activity can specify the task stack), then the instance will not be recreated when the Activity is started, and the onNewIntent method of the Activity will be called. (Note: In this mode, it has the effect of clearTop by default, which causes all the activities above the Activity to pop out of the stack.)

    singleInstance: An enhanced version of singleTask, which has all the features of the singleTask mode, plus a little more. In this mode, an Activity can only be located in a single task stack.

 

2, TaskAffinity role:

This parameter identifies the name of the task stack required by an Activity. By default, the name of the task stack required by all activities is the package name. The TaskAffinity property can also be specified separately (it cannot be the same as the package name, otherwise it is the same as not specified).

3. Activity's Flags

FLAG_ACTIVITY_NEW_TASK : The role of this flag bit is to specify the "singleTask" startup mode,

FLAG_ACTIVITY_SINGLE_TOP : The role of this flag bit is to specify the "singleTop" startup mode,

FLAG_ACTIVITY_CLEAR_TOP : When the specified Activity is started, the Activity above it with the same task stack will be cleared.

FLAG_ACTIVITY_EXCLUB_FROM_RECENTS: The started Activity will not appear in the historical Activity list. In some cases, the user does not want to return to our Activity through the history list.

 

4, IntentFilter matching rules

    1. An Activity can have multiple Intent-filters, and each Intent can successfully start the corresponding Activity as long as it matches a set of Intent-filters

    Action matching rules:

    Intent contains multiple actions, one of which can be the same as any action in the filter rule even if the match is successful. If no action is specified, the match will fail.

    category matching rules

    An Intent can contain multiple categories. If all categories match the filter rules, the match is considered successful. Matching is possible without Category. The default Intent will add the category android.intent.category.DEFAULT, so the intent can match successfully without any category. (activity) To be able to receive implicit calls, you must specify the category android.intent.category.DEFAULT in the intent-filter)

    data matching rules

    The data rule is similar to the action. If the data is defined in the rule, the matching data must also be defined in the intent (one-to-one correspondence)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325363617&siteId=291194637