Intent总结

来源:互联网 发布:linux怎么关机 编辑:程序博客网 时间:2024/05/21 09:46

Intent是一个消息传递对象,您可以使用它从另一个应用程序组件请求操作。 尽管意图以多种方式促进组件之间的通信,但是存在三种基本使用情况:

启动activity


启动service、broadcast


intent对象包括一下七种属性
Component、Action、Category、Data、Type、Extra、Flag.其中Component明确指定需要启动的组件,既显示启动。Extra用来携带数据。Flag用于指定启动模式。Action、Category、Data、Type 匹配组件intentfilter标签,既隐式启动某个组件。





------当data和type属性都要设置时必须用此方法。




public Intent setFlags (int flags)

设置控制如何处理此意图的特殊标志。既将要启动的组件设置为何种模式。具体每种flag含义可参考API文档 。大多数值在这里取决于Intent正在执行的组件的类型,具体来说,FLAG_ACTIVITY_ *标志全部用于Context.startActivity(),而FLAG_RECEIVER_ *标志都用于Context.sendBroadcast()。

一下列举些:

FLAG_ACTIVITY_BROUGHT_TO_FRONT


FLAG_ACTIVITY_CLEAR_TASK


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.


FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET


FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS


FLAG_ACTIVITY_FORWARD_RESULT


FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY


FLAG_ACTIVITY_MULTIPLE_TASK


FLAG_ACTIVITY_NEW_DOCUMENT


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 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.


FLAG_ACTIVITY_NO_ANIMATION


FLAG_ACTIVITY_NO_HISTORY


FLAG_ACTIVITY_NO_USER_ACTION


FLAG_ACTIVITY_PREVIOUS_IS_TOP


FLAG_ACTIVITY_RESET_TASK_IF_NEEDED


FLAG_ACTIVITY_REORDER_TO_FRONT


FLAG_ACTIVITY_SINGLE_TOP


FLAG_ACTIVITY_TASK_ON_HOME:
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.(此标志这只能与FLAG_ACTIVITY_NEW_TASK一起使用。)




0 0