您的位置:首页 > 移动开发 > Android开发

什么时候加上android.intent.category.DEFAULT

2013-02-10 10:30 351 查看
In principle, therefore, an Intent object with no categories should always pass this test, regardless of what's in the filter. That's
mostly true. However, with one exception, Android treats all implicit intentspassed to
startActivity()
as
if they contained at least one category: "
android.intent.category.DEFAULT
"
(the
CATEGORY_DEFAULT
constant).
Therefore, activities that are willing to receive implicit intents must include "
android.intent.category.DEFAULT
"
in their intent filters. (Filters with "
android.intent.action.MAIN
"
and "
android.intent.category.LAUNCHER
"
settings are the exception. They mark activities that begin new tasks and that are represented on the launcher screen. They can include "
android.intent.category.DEFAULT
"
in the list of categories, but don't need to.) See Using
intent matching, later, for more on these filters.)
http://developer.android.com/guide/components/intents-filters.html
意思是说,每一个通过 startActivity() 方法发出的隐式 Intent 都至少有一个 category,就是 "
android.intent.category.DEFAULT
",所以只要是想接收一个隐式 Intent
的 Activity 都应该包括 "
android.intent.category.DEFAULT
" category,不然将导致 Intent 匹配失败。

从上面的论述还可以获得以下信息:

1、一个 Intent 可以有多个 category,但至少会有一个,也是默认的一个 category。

2、只有 Intent 的所有 category 都匹配上,Activity 才会接收这个 Intent。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: