android api文档:intent阅读笔记

本文详细介绍了Android系统中Intent与IntentFilter的工作原理及其组成部分,包括Component、Action、Data、Category、Extras和Flags等,并解释了它们如何在组件间通信。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

intent是几大组件之间进行通信的组件。可以包含以下几个部分:

component:指明了处理该intent的对象。

Action类似于一个函数名,规定了其他部分的对应用法:

The action largely determines how the rest of the intent is structured — particularly the data and extras fields — much as a method name determines a set of arguments and a return value.

Data就是一个Uri:

In many cases, the data type can be inferred from the URI — particularly content: URIs, which indicate that the data is located on the device and controlled by a content provider Category:一个字符串: A string containing additional information about the kind of component that should handle the intent. Any number of category descriptions can be placed in an Intent object.

category:一个字符串

A string containing additional information about the kind of component that should handle the intent. Any number of category descriptions can be placed in an Intent object.

Extras: 是一组键值对:

Key-value pairs for additional information that should be delivered to the component handling the intent. Just as some actions are paired with particular kinds of data URIs, some are paired with particular extras. . These methods parallel those for Bundle objects

Flags一些常数字

Flags of various sorts. Many instruct the Android system how to launch an activity (for example, which task the activity should belong to) and how to treat it after it's launched (for example, whether it belongs in the list of recent activities). 

不过以上这些组件在解析对应的intent时候,

Only three aspects of an Intent object are consulted when the object is tested against an intent filter:

action  data (both URI and data type)  category

The extras and flags play no part in resolving which component receives an intent.

与之对应的intentFilter,

A filter has fields that parallel the action, data, and category fields of an Intent object. An implicit intent is tested against the filter in all three areas. To be delivered to the component that owns the filter, it must pass all three tests. 

(至于intent和intent filter详细的匹配规则可以参照具体的api文档,尤其是关于data的匹配规则相对复杂:

Since most available data is dispensed by content providers, filters that specify a data type but not a URI are perhaps the most common

 

 

 

转载于:https://www.cnblogs.com/bobodeboke/p/3179576.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值