Intent resolution

佐手、 提交于 2019-12-05 13:01:39

Intent resolution,是指Android系统如何将一个intent请求匹配到一个已经在系统中注册的组件的(activity,service,broadcast receiver)。根据《Unlocking Android》书中描述,intent解析有两个最基本的原则:

1、The action and category must match.

2、If specified, the data type must match, or the combination of data scheme and authority and path must match.

一般情况下,intent-filter中只要包含action和category就足以满足很多需求。在实际解析过程中,如果一个组件的intent-filter中没有声明任何action,那么任何intent都能与该组件的action相匹配;但是如果一个intent-filter中没有声明任何category,那么这个组件只能与没有指定任何category的intent相匹配。需要注意的是:在隐式调用activity时,系统会自动给intent中加入android.intent.category.DEFAULT的category,所以如果一个intent-filter中不声明Ddefault的category就会导致intent匹配不到任何组件。

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!