Intent学习笔记整理

Intent在Android中起到消息传递的作用,是组件间通信的重要桥梁。它包含Action、Data、Category、Type等属性,用于描述操作行为、操作数据、附加信息等。通过IntentFilter匹配,系统可以找到合适的Activity、BroadcastReceiver或Service来处理Intent。直接Intent指定目标组件,而间接Intent需要系统解析。解析过程中,Action、Data、Type、Category等需与组件的IntentFilter匹配。
摘要由CSDN通过智能技术生成

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是一系列的可选动作中的一个,这些动作

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值