Intent FLAG详解

Intent FLAG详解

public static final int FLAG_ACTIVITY_NEW_TASK

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 the Application Model documentation for
more details on 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 (0x10000000)


public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT

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 (0x00400000)


public static final int FLAG_ACTIVITY_CLEAR_TOP

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 task B in the above example will either
receiving the new intent you are starting here in its onNewIntent() method,
or be itself finished and restarting with the new intent. If it has declared
its launch mode to be "multiple" (the default) it will be finished and
re-created; for all other launch modes it will receive the Intent in the current instance.

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 the Application Model documentation for more details on tasks.
Constant Value: 67108864 (0x04000000)


public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

If set, the new activity is not kept in the list of recently
launched activities.
Constant Value: 8388608 (0x00800000)


public static final int FLAG_ACTIVITY_FORWARD_RESULT

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 (0x02000000)

public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY

If set, this activity is being launched from history (longpress home key).
Constant Value: 1048576 (0x00100000)

public static final int FLAG_ACTIVITY_MULTIPLE_TASK

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 the Application Model documentation for more details on tasks.
Constant Value: 134217728 (0x08000000)


public static final int FLAG_ACTIVITY_NEW_TASK

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 the Application
Model documentation for more details on 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 (0x10000000)


public static final int FLAG_ACTIVITY_NO_HISTORY

If set, the new activity is not kept in the history stack.
Constant Value: 1073741824 (0x40000000)


public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP

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 (0x01000000)


public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED


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 (0x00200000)


public static final int FLAG_ACTIVITY_SINGLE_TOP

If set, the activity will not be launched if it is
already running at the top of the history stack.
Constant Value: 536870912 (0x20000000)


public static final int FLAG_DEBUG_LOG_RESOLUTION

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 (0x00000008)


public static final int FLAG_FROM_BACKGROUND

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 (0x00000004)


public static final int FLAG_GRANT_READ_URI_PERMISSION

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 (0x00000001)

public static final int FLAG_GRANT_WRITE_URI_PERMISSION

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 (0x00000002)

public static final int FLAG_RECEIVER_REGISTERED_ONLY
If set, when sending a broadcast only registered receivers will be
called -- no BroadcastReceiver components will be launched.
Constant Value: 1073741824 (0x40000000)

FLAG_ACTIVITY_BROUGHT_TO_FRONT

This flag is not normally set by application code, but set for you by the system for the singleTask mode activity.

FLAG_ACTIVITY_CLEAR_TOP

砍掉本任务栈里在被启动Activity之上的所有Activity。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. 此时如果Activity B的启动模式是默认的multiple,且没有设置 FLAG_ACTIVITY_SINGLE_TOP,那么B会被结束并重建,反之B的onNewIntent()会被调用,不用重建。如果和 FLAG_ACTIVITY_NEW_TASK搭配,则会在别的任务栈(优先选择后台任务栈,其次考虑新建任务栈)里产生同样效果,这点很有用,比如用在Notification manager里启动一个Activity。

FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

如果设置,这将在Task的Activity stack中设置一个还原点,当Task恢复时,需要清理Activity。也就是说,下一次Task带着 FLAG_ACTIVITY_RESET_TASK_IF_NEEDED标记进入前台时(典型的操作是用户在主画面重启它),这个Activity和它之 上的都将关闭,以至于用户不能再返回到它们,但是可以回到之前的Activity。
    这在你的程序有分割点的时候很有用。例如,一个e-mail应用程序可能有一个操作是查看一个附件,需要启动图片浏览Activity来显示。这个 Activity应该作为e-mail应用程序Task的一部分,因为这是用户在这个Task中触发的操作。然而,当用户离开这个Task,然后从主画面 选择e-mail app,我们可能希望回到查看的会话中,但不是查看图片附件,因为这让人困惑。通过在启动图片浏览时设定这个标志,浏览及其它启动的Activity在下 次用户返回到mail程序时都将全部清除。

FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

如果设置,新的Activity不会在最近启动的Activity的列表中保存。FLAG_ACTIVITY_FORWARD_RESULT 

如果设置,并且这个Intent用于从一个存在的Activity启动一个新的Activity,那么,这个作为答复目标的Activity将会传 到这个新的Activity中。这种方式下,新的Activity可以调用setResult(int),并且这个结果值将发送给那个作为答复目标的 Activity。总而言之,当一个結果需要运行多个Activity才能得到时用这个flag来传递答复目标。

FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY

通常由系统来设置这个flag,if this activity is being launched from history (longpress home key)。

FLAG_ACTIVITY_MULTIPLE_TASK

不要使用这个标志,除非你自己实现了应用程序启动器。与FLAG_ACTIVITY_NEW_TASK结合起来使用,可以禁用把已存的Task送入前台的行为。当设置时,新的Task总是会启动来处理Intent,而不管这是是否已经有一个Task可以处理相同的事情。经 过实践,当Activity的launchMode为singleStask时此flag无效,还是把已经启动过的那个Activity放到前台,因此相 信singleInstance的Activity同样无效。这是合理的,因为这两种lauchMode的Activity本来在全局范围内就只能有一个 实例。

由于默认的系统不包含图形Task管理功能,因此,你不应该使用这个标志,除非你提供给用户一种方式可以返回到已经启动的Task。

如果FLAG_ACTIVITY_NEW_TASK标志没有设置,这个标志被忽略。

FLAG_ACTIVITY_NEW_TASK

如果设置,这个Activity会在一个新建Task的栈顶启动 (这是不一定的,只有该Activity的taskAffinity和当前所有Task(包括当前Task)的affinity不匹配时才成立)。一个Task(从启动它的Activity到下一个Task中的Activity)定义了用户可以迁移的Activity原子组。Task可以移动到前台和后台;在某个特定Task中的所有Activity总是保持相同的次序。

这个标志一般用于呈现“启动”类型的行为:它们提供用户一系列可以单独完成的事情,与启动它们的Activity完全无关。

使用这个标志,如果正在启动的Activity的Task(即以此Activity为栈底的Task)已经在运行的话,那么,新的Activity将不会启动,代替的,这个Task会简单的移入前台(如果它已经在前台的话就什么都不会发生)。参考FLAG_ACTIVITY_MULTIPLE_TASK标志,可以禁用这一行为。如果没有以此Activity为栈底的Task在运行的话就会在一个有相同affinity的Task(没有就新建Task)的栈顶启动此Activity。

这个标志不能用于调用方为了请求結果而启动Activity。因为被启动的Activity和调用方不在同一个进程中,调用方会收到RESULT_CANCELED。

FLAG_ACTIVITY_NO_ANIMATION

在启动Activity的时候不要过渡动画。

FLAG_ACTIVITY_NO_HISTOR

如果设置,新的Activity将不在任务栈中保留。用户一离开它,这个Activity就关闭了。这也可以通过设置noHistory特性。

 FLAG_ACTIVITY_SINGLE_TOP

If set, the activity will not be launched if it is already running at the top of the history stack. Instead the onNewIntent() will be called.

猜你喜欢

转载自yulincqupt.iteye.com/blog/1756693