Intent探索

intent的分类

Intent分为两种,显式intent和隐式intent,显式intent直接指明了接收的Activity,隐式intent没有直接指出接收的Activity,而是需要去AndroidManifest.xml文件中去匹配。Activity匹配隐式intent的条件有三个,Action,Category,Data这三个条件均位于intent-filter标签。Android本身库中提供了标准的Action和Category库,定义了data的格式。

intent的官方描述

An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.

An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.

常用的函数

构造函数

intent的构造函数

高频函数

setClass()
setAction()
setdata()

intent-filter实例

<intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <action android:name="android.intent.action.EDIT" />
     <action android:name="android.intent.action.PICK" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
 </intent-filter>

注意事项:
1. 隐式intent查询时的优先级为action->data->category
2. action的值就是一个字符串,可以随意设置,只要匹配就可以

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值