Intent学习

来源:互联网 发布:distinct sql 用法 编辑:程序博客网 时间:2024/05/29 18:43

简介:

intent 可以启动一个activity,broadcast或者service,实现一种运行时的绑定。

intent 结构

最重要的两个信息是

  • action -- The general action to be performed, such as ACTION_VIEWACTION_EDITACTION_MAIN, etc.

  • data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri

其他信息:
  • category -- Gives additional information about the action to execute. For example, CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can perform on a piece of data.

  • type -- 指定传递的数据类型(使用 MIME type) 

  • component -- 显式的指定了处理intent的组件

  • extras -- This is a Bundle of any additional information. This can be used to provide extended information to the component. For example, if we have a action to send an e-mail message, we could also include extra pieces of data here to supply a subject, body, etc.

  • 总而言之, the set of actions, data types, categories, and extra data defines a language for the system allowing for the expression of phrases such as “call john smith's cell

Intent有两种形式:
显式:指定要处理Intent的组件,通过 setComponent(ComponentName) 或者setClass(Context, Class),常用于启动同一个应用内的活动。
隐式:Intent定义好信息后,由系统的Intent resolution来进行匹配, which maps an Intent to an ActivityBroadcastReceiver, or Service (or sometimes two or more activities/receivers) that can handle it.
Intent resolution 将Intent与安装好的应用包中的意图过滤器进行比对从而确定谁来响应。
只比对三个信息:action, type, and category


0 0
原创粉丝点击