`
yxwang0615
  • 浏览: 559721 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

Activity 的Task与Intent FLAG

 
阅读更多

Task是包含一系列Activity的堆栈, 遵循先进后出原则.,一个应用程序中的所有activity共有一个Task堆栈,可通过Context.getTaskId()打印查看。

 

 

 

public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT
Since: API Level 1

This flag is not normally set by application code, but set for you by the system as described in the launchMode documentation for the singleTask mode.
Constant Value: 4194304 (0×00400000)
public static final int FLAG_ACTIVITY_CLEAR_TASK
Since: API Level 11

If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.
Constant Value: 32768 (0×00008000)
public static final int FLAG_ACTIVITY_CLEAR_TOP
Since: API Level 1

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

For example, consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receive the given Intent, resulting in the stack now being: A, B.

The currently running instance of activity B in the above example will either receive the new intent you are starting here in its onNewIntent() method, or be itself finished and restarted with the new intent. If it has declared its launch mode to be “multiple” (the default) and you have not set FLAG_ACTIVITY_SINGLE_TOP in the same intent, then it will be finished and re-created; for all other launch modes or if FLAG_ACTIVITY_SINGLE_TOP is set then this Intent will be delivered to the current instance’s onNewIntent().

This launch mode can also be used to good effect in conjunction with FLAG_ACTIVITY_NEW_TASK: if used to start the root activity of a task, it will bring any currently running instance of that task to the foreground, and then clear it to its root state. This is especially useful, for example, when launching an activity from the notification manager.

See Tasks and Back Stack for more information about tasks.
Constant Value: 67108864 (0×04000000)
public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
Since: API Level 3

If set, this marks a point in the task’s activity stack that should be cleared when the task is reset. That is, the next time the task is brought to the foreground with FLAG_ACTIVITY_RESET_TASK_IF_NEEDED (typically as a result of the user re-launching it from home), this activity and all on top of it will be finished so that the user does not return to them, but instead returns to whatever activity preceeded it.

This is useful for cases where you have a logical break in your application. For example, an e-mail application may have a command to view an attachment, which launches an image view activity to display it. This activity should be part of the e-mail application’s task, since it is a part of the task the user is involved in. However, if the user leaves that task, and later selects the e-mail app from home, we may like them to return to the conversation they were viewing, not the picture attachment, since that is confusing. By setting this flag when launching the image viewer, that viewer and any activities it starts will be removed the next time the user returns to mail.
Constant Value: 524288 (0×00080000)
public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Since: API Level 1

If set, the new activity is not kept in the list of recently launched activities.
Constant Value: 8388608 (0×00800000)
public static final int FLAG_ACTIVITY_FORWARD_RESULT
Since: API Level 1

If set and this intent is being used to launch a new activity from an existing one, then the reply target of the existing activity will be transfered to the new activity. This way the new activity can call setResult(int) and have that result sent back to the reply target of the original activity.
Constant Value: 33554432 (0×02000000)
public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
Since: API Level 1

This flag is not normally set by application code, but set for you by the system if this activity is being launched from history (longpress home key).
Constant Value: 1048576 (0×00100000)
public static final int FLAG_ACTIVITY_MULTIPLE_TASK
Since: API Level 1

Do not use this flag unless you are implementing your own top-level application launcher. Used in conjunction with FLAG_ACTIVITY_NEW_TASK to disable the behavior of bringing an existing task to the foreground. When set, a new task is always started to host the Activity for the Intent, regardless of whether there is already an existing task running the same thing.

Because the default system does not include graphical task management, you should not use this flag unless you provide some way for a user to return back to the tasks you have launched.

This flag is ignored if FLAG_ACTIVITY_NEW_TASK is not set.

See Tasks and Back Stack for more information about tasks.
Constant Value: 134217728 (0×08000000)
public static final int FLAG_ACTIVITY_NEW_TASK
Since: API Level 1

If set, this activity will become the start of a new task on this history stack. A task (from the activity that started it to the next task activity) defines an atomic group of activities that the user can move to. Tasks can be moved to the foreground and background; all of the activities inside of a particular task always remain in the same order. See Tasks and Back Stack for more information about tasks.

This flag is generally used by activities that want to present a “launcher” style behavior: they give the user a list of separate things that can be done, which otherwise run completely independently of the activity launching them.

When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in. See FLAG_ACTIVITY_MULTIPLE_TASK for a flag to disable this behavior.

This flag can not be used when the caller is requesting a result from the activity being launched.
Constant Value: 268435456 (0×10000000)
public static final int FLAG_ACTIVITY_NO_ANIMATION
Since: API Level 5

If set in an Intent passed to Context.startActivity(), this flag will prevent the system from applying an activity transition animation to go to the next activity state. This doesn’t mean an animation will never run — if another activity change happens that doesn’t specify this flag before the activity started here is displayed, then that transition will be used. This flag can be put to good use when you are going to do a series of activity operations but the animation seen by the user shouldn’t be driven by the first activity change but rather a later one.
Constant Value: 65536 (0×00010000)
public static final int FLAG_ACTIVITY_NO_HISTORY
Since: API Level 1

If set, the new activity is not kept in the history stack. As soon as the user navigates away from it, the activity is finished. This may also be set with the noHistory attribute.
Constant Value: 1073741824 (0×40000000)
public static final int FLAG_ACTIVITY_NO_USER_ACTION
Since: API Level 3

If set, this flag will prevent the normal onUserLeaveHint() callback from occurring on the current frontmost activity before it is paused as the newly-started activity is brought to the front.

Typically, an activity can rely on that callback to indicate that an explicit user action has caused their activity to be moved out of the foreground. The callback marks an appropriate point in the activity’s lifecycle for it to dismiss any notifications that it intends to display “until the user has seen them,” such as a blinking LED.

If an activity is ever started via any non-user-driven events such as phone-call receipt or an alarm handler, this flag should be passed to Context.startActivity, ensuring that the pausing activity does not think the user has acknowledged its notification.
Constant Value: 262144 (0×00040000)
public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP
Since: API Level 1

If set and this intent is being used to launch a new activity from an existing one, the current activity will not be counted as the top activity for deciding whether the new intent should be delivered to the top instead of starting a new one. The previous activity will be used as the top, with the assumption being that the current activity will finish itself immediately.
Constant Value: 16777216 (0×01000000)
public static final int FLAG_ACTIVITY_REORDER_TO_FRONT
Since: API Level 3

If set in an Intent passed to Context.startActivity(), this flag will cause the launched activity to be brought to the front of its task’s history stack if it is already running.

For example, consider a task consisting of four activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then B will be brought to the front of the history stack, with this resulting order: A, C, D, B. This flag will be ignored if FLAG_ACTIVITY_CLEAR_TOP is also specified.
Constant Value: 131072 (0×00020000)
public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
Since: API Level 1

If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task. This will result in the application of any affinities needed to have that task in the proper state (either moving activities to or from it), or simply resetting that task to its initial state if needed.
Constant Value: 2097152 (0×00200000)
public static final int FLAG_ACTIVITY_SINGLE_TOP
Since: API Level 1

If set, the activity will not be launched if it is already running at the top of the history stack.
Constant Value: 536870912 (0×20000000)
public static final int FLAG_ACTIVITY_TASK_ON_HOME
Since: API Level 11

If set in an Intent passed to Context.startActivity(), this flag will cause a newly launching task to be placed on top of the current home activity task (if there is one). That is, pressing back from the task will always return the user to home even if that was not the last activity they saw. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.
Constant Value: 16384 (0×00004000)
public static final int FLAG_DEBUG_LOG_RESOLUTION
Since: API Level 1

A flag you can enable for debugging: when set, log messages will be printed during the resolution of this intent to show you what has been found to create the final resolved list.
Constant Value: 8 (0×00000008)
public static final int FLAG_EXCLUDE_STOPPED_PACKAGES
Since: API Level 12

If set, this intent will not match any components in packages that are currently stopped. If this is not set, then the default behavior is to include such applications in the result.
Constant Value: 16 (0×00000010)
public static final int FLAG_FROM_BACKGROUND
Since: API Level 1

Can be set by the caller to indicate that this Intent is coming from a background operation, not from direct user interaction.
Constant Value: 4 (0×00000004)
public static final int FLAG_GRANT_READ_URI_PERMISSION
Since: API Level 1

If set, the recipient of this Intent will be granted permission to perform read operations on the Uri in the Intent’s data.
Constant Value: 1 (0×00000001)
public static final int FLAG_GRANT_WRITE_URI_PERMISSION
Since: API Level 1

If set, the recipient of this Intent will be granted permission to perform write operations on the Uri in the Intent’s data.
Constant Value: 2 (0×00000002)
public static final int FLAG_INCLUDE_STOPPED_PACKAGES
Since: API Level 12

If set, this intent will always match any components in packages that are currently stopped. This is the default behavior when FLAG_EXCLUDE_STOPPED_PACKAGES is not set. If both of these flags are set, this one wins (it allows overriding of exclude for places where the framework may automatically set the exclude flag).
Constant Value: 32 (0×00000020)
public static final int FLAG_RECEIVER_REGISTERED_ONLY
Since: API Level 1

If set, when sending a broadcast only registered receivers will be called — no BroadcastReceiver components will be launched.
Constant Value: 1073741824 (0×40000000)
public static final int FLAG_RECEIVER_REPLACE_PENDING
Since: API Level 8

If set, when sending a broadcast the new broadcast will replace any existing pending broadcast that matches it. Matching is defined by Intent.filterEquals returning true for the intents of the two broadcasts. When a match is found, the new broadcast (and receivers associated with it) will replace the existing one in the pending broadcast list, remaining at the same position in the list.

This flag is most typically used with sticky broadcasts, which only care about delivering the most recent values of the broadcast to their receivers.
Constant Value: 536870912 (0×20000000)
public static final String METADATA_DOCK_HOME
Since: API Level 5

Boolean that can be supplied as meta-data with a dock activity, to indicate that the dock should take over the home key when it is active.
Constant Value: “android.dock_home”
public static final int URI_INTENT_SCHEME
Since: API Level 4

Flag for use with toUri(int) and parseUri(String, int): the URI string always has the “intent:” scheme. This syntax can be used when you want to later disambiguate between URIs that are intended to describe an Intent vs. all others that should be treated as raw URIs. When used with parseUri(String, int), any other scheme will result in a generic VIEW action for that raw URI.
Constant Value: 1 (0×00000001)

 

 

 

 

分享到:
评论

相关推荐

    Activity启动模式及Intent的Flag属性对Intent传值的影响

    - **FLAG_ACTIVITY_NEW_TASK**:常用于启动新的任务栈,与SingleTask启动模式相似,常在BroadcastReceiver中使用。 - **FLAG_ACTIVITY_SINGLE_TOP**:与SingleTop启动模式类似,使得已存在的Activity实例被调用,...

    android Intent.FLAG大全

    了解和正确使用这些`Intent.FLAG`可以优化Android应用的用户体验,避免不必要的Activity创建,提升性能,同时确保用户导航的合理性和一致性。在实际开发中,开发者应结合具体场景灵活运用,以实现预期的行为。

    Activity之间的Intent跳转

    比如,`FLAG_ACTIVITY_NEW_TASK`用于在新的任务中启动Activity,`FLAG_ACTIVITY_CLEAR_TOP`则会清除栈顶到目标Activity的所有Activity。 6. **结果回调**: 如果需要从启动的Activity得到返回结果,可以使用`...

    android activity和task

    - 当使用`Intent.FLAG_ACTIVITY_NEW_TASK`启动Activity时,系统会检查是否有与Activity Affinity相同的Task,如果有,就将Activity添加到那个Task,否则创建新的Task。 4. Manifest文件中的Activity属性: - `...

    第3章 Activity与Intent.pptx

    在Intent中,可以设置FLAG_ACTIVITY_NEW_TASK标志来创建新的任务栈,或者使用FLAG_ACTIVITY_CLEAR_TOP清除栈顶到目标Activity之间的所有Activity,使目标Activity重新获得焦点。 总的来说,Activity和Intent是...

    Android提高第四篇之Activity+Intent.docx

    Intent还可以携带FLAG,比如FLAG_ACTIVITY_NEW_TASK用于在新的任务栈中启动Activity,FLAG_ACTIVITY_CLEAR_TOP则会清除当前Activity之上所有Activity,使目标Activity回到栈顶。 在AndroidManifest.xml中声明...

    ex07_activity_intent.rar_Intent_android

    Intent还支持各种FLAG,如`FLAG_ACTIVITY_NEW_TASK`用于在新的任务栈中启动Activity,`FLAG_ACTIVITY_CLEAR_TOP`则会清除所有栈上的Activity,只保留目标Activity。此外,还可以使用`FLAG_INCLUDE_STOPPED_PACKAGES...

    Intent的Activity转向

    例如,FLAG_ACTIVITY_NEW_TASK用于在新的任务栈中启动Activity,FLAG_ACTIVITY_CLEAR_TOP则会清除所有位于目标Activity之上的Activity。 6. BroadcastReceiver与Intent: 除了Activity,Intent还可以用于触发...

    android=activity+intent=dome

    6. 深浅复制Intent和Activity栈的概念:理解Task和Back Stack,以及如何通过FLAG控制Activity的启动模式。 通过这样的实践项目,开发者不仅可以巩固理论知识,还能提升实际编程技能,为后续更复杂的Android应用开发...

    android开发中Intent在两个Activity间传值示例

    可以使用不同的Flag来控制Intent的行为,如`FLAG_ACTIVITY_NEW_TASK`用于在新的任务栈中启动Activity,`FLAG_ACTIVITY_CLEAR_TOP`用于清除栈顶Activity并重新打开目标Activity。 通过以上讲解,我们可以看到Intent...

    Android的Intent实验

    - `setFlags()`: 设置Intent的标志,影响Intent的处理方式,如FLAG_ACTIVITY_NEW_TASK用于在新的任务栈中启动Activity。 5. **启动Activity** 使用`startActivity(Intent)`方法启动一个Activity。如果Intent是...

    安卓Android源码——(Activity跳转与操作).zip

    8. 使用Intent Flag可以控制Activity的行为,如FLAG_ACTIVITY_NEW_TASK开启新任务,FLAG_ACTIVITY_CLEAR_TOP回到栈顶Activity并清除上面的Activity等。 七、Activity结果的接收 9. 使用startActivityForResult()...

    Intent跳转的三种写法

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); ``` 2. `FLAG_ACTIVITY_CLEAR_TOP`:当目标Activity已经在任务栈中时,会把栈顶到目标Activity的所有Activity都移除,然后重新创建目标...

    android之intent&activity;生命周期

    一些常见的Flag包括FLAG_ACTIVITY_CLEAR_TASK、FLAG_ACTIVITY_NEW_TASK、FLAG_ACTIVITY_NO_HISTORY和FLAG_ACTIVITY_SINGLE_TOP。 Intent的作用非常广泛,可以用来启动Activity、Service、Broadcast等。例如,启动一...

    Activity,回退栈,Task之间的关系

    - 跨应用启动 Activity 时,可以通过设置 `Intent` 的标志符(如 `FLAG_ACTIVITY_NEW_TASK`)以及配置 Activity 的 `taskAffinity` 来控制 Activity 是否位于一个新的 Task 中。 - 默认情况下,Activity 的 `...

    安全退出activity方法(多种)

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); ``` 4. 利用广播:创建一个自定义广播接收器,当接收到特定广播时,触发Activity的`finish()`方法。...

    Intent系统调用示例

    - 可能还涉及到Intent Flag的使用,如`FLAG_ACTIVITY_NEW_TASK`、`FLAG_ACTIVITY_CLEAR_TOP`等,控制Activity的启动行为。 5. **IntentFilter** 对于隐式Intent,接收者需要通过IntentFilter声明可以响应哪些...

    经典的android intent 窗口切换 窗口打开

    Intent Flag可以控制Activity的启动行为,例如`FLAG_ACTIVITY_NEW_TASK`表示在新的任务栈中启动Activity,`FLAG_ACTIVITY_CLEAR_TOP`表示清除栈顶到目标Activity之间的所有Activity。 8. **Intent Filter** 隐式...

    android代码 Activity跳转

    例如,FLAG_ACTIVITY_CLEAR_TOP可以清除栈上所有Activity,FLAG_ACTIVITY_NEW_TASK用于在新的任务栈中启动Activity。 总结,Activity跳转是Android开发中不可或缺的部分,理解Intent、启动模式以及返回结果的处理...

    Android 改变Activity切换方式

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); ``` 另外,我们还可以通过修改AndroidManifest.xml中Activity的`android:launchMode`属性来全局设定Activity的启动模式,它有四个可选值...

Global site tag (gtag.js) - Google Analytics