Intents and Intent Filters

1、通过Intent启动的3种组件:activity、service、broadcast receiver。
Intent启动activity:
	startActivity():
	startActivityForResult():setResult()返回结果。
Intent启动service:
	startService():
	bindService():
Intent启动broadcast server:
	sendBroadcast():
	sendOrderedBroadcast():
	sendStickyBroadcast():
Intent:一组系统启动组件需要的信息。
组件名:组件类全名。设置:setComponent(),setClass(),setClassName();获取:getComponent()。
Action:需要activity、service执行的动作,或者broadcast正在发生的动作。Intent类中预定义了一部分常量;可自定义包名.action名的动作。设置:setAction();读:getAction()。
Data--uri:与Action配对的数据URI、数据MIME类型。如ACTION_CALL配tel:URI;ACTION_VIEW配http:URI。content:URI来自content provider的数据经常需要知道MINE类型。设置:setData()、setDataAndType();读:getData()、getType()。
Category:缩小可处理该Intent的组件的范围。Intent中预定义了常量。设置:addCategory()、removeCategory();读:getCategories()。
Extras:额外的K-V值信息。key因Action而定。设置:putExtras();读:getExtras()。
Flags:指示Android如何启动组件,如新activity所属的task。

2. Intent解析:
显式Explicit intent:明确指定组件名;主要用于app内部调用。
隐式Implicit intent:不指定组件名;主要用于app之间调用,Android通过action、data(URI、type)、category与Intent filters比较选择合适的组件。

3. Intent filters:告诉系统组件可以处理的implicit intent,通过action、data、category。
健壮性考虑:activity声明的Intent filters设计为处理implicit intent,即intent应带有符合声明的action、URI、type、category;但同时可以用explicit intent直接调用,intent中的action、data、category可能不符合声明,需要考虑健壮性。
通常每一项filter声明一项组件功能。<action>声明中至少应有一项匹配intent中的action,<category>的default是可被Android启动的默认匹配类别,<launcher>是例外。<data mineType URI>由mineType、schema://host:port/path组成,host:port合称authority;intent filter中可以只指定schema,或者schema://authority;mineType可以为type/*;filter中声明的data对intent中的data严格匹配,除content:与file:两种URI外,此时假设数据由content provider、本地文件提供。
PackageManager可根据intent filter列出可处理某个intent的响应组件列表,如queryIntentActivities() 、queryIntentServices()、queryBroadcastReceivers();
原文地址:https://www.cnblogs.com/toven/p/2641125.html