1.Intent概念
根据开发文档上的描述——“Intent是对一个执行操作的抽象描述”。
个人理解:Intent像是一个媒介,或者说信使,提供组件相互调用的信息。
而在Intent中包含的信息包括对一次操作的动作、该动作涉及的数据、附加数据的描述。其中最重要的是前动作和动作对应的数据。
2.Intent属性
1>Action ,也就是对动作的描述。是个字符串,是对所将执行的动作的描述,在Intent类中定义了一些字符串常量作为标准动作。
标准的activity的Action可以自行查看文档(android developer网登陆不了的可以在这里查看)
最常用的两个动作是ACTION_MAIN,ACTION_EDIT
此外,可以自己定义Action
2>Data,即动作要操作的数据,以URI的形式表示。譬如在联系人应用中,指向联系人1的URI可能为:content://contacts/1 (由content provider提供的数据类型是content) 。 结合Action和data可以基本表达出意图:
-
ACTION_VIEW
content://contacts/people/1 -- Display information about the person whose identifier is "1". -
ACTION_DIAL
content://contacts/people/1 -- Display the phone dialer with the person filled in. -
ACTION_VIEW
tel:123 -- Display the phone dialer with the given number filled in. Note how the VIEW action does what what is considered the most reasonable thing for a particular URI. -
ACTION_DIAL
tel:123 -- Display the phone dialer with the given number filled in. -
ACTION_EDIT
content://contacts/people/1 -- Edit information about the person whose identifier is "1". -
ACTION_VIEW
content://contacts/people/ he-- Display a list of people, which t user can browse through.注意对于不同的动作,其URI数据的类型是不同的(可以设置type属性指定特定类型数据),如ACTION_EDIT指定Data为文件URI,打电话为tel:URI,访问网络为http:URI,而由content provider提供的数据则为
content:
URIs
此外,还有一些其他属性:
3>category,被执行的动作的附加信息。如 LAUNCHER_CATEGORY 表示Intent 的接受者应该在Launcher中作为顶级应用出现;而ALTERNATIVE_CATEGORY表示当前的Intent是一系列的可选动作中的一个,这些动作