intent:翻译为意图,是android组件间或者应用间跳转传递数据的一种方式。分为显式启动,隐式启动两种方式。
intent的六种属性:
component name 组件名 指定启动组件的名字,一般用于一个应用内部的显示启动
category 种类 没有指定则为默认default
action 动作 指定将要启动的应用将要做什么 例如打电话 一般用于进程间通讯,隐式启动
data 数据 指定数据包括type和uri(唯一资源定位符) 两部分
extras 额外的数据 一个键值对
flag 启动模式
intent filter的匹配:
intent和intent filter配套使用,通过intent filter来匹配发送的intent。
intent filter写在manifest里面例如:
<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
每个组件可以有若干个intent filter,影响匹配的只有category,action,data不包括extras,flag。
其中data比较复杂:
mime type:
类型/子类型
application/javascript
application/zip
audio/mp3
audio/quicktime
video/mp4
text/html
text/XML
text/plain
image/jpeg
image/png
image/*
uri:
scheme://host:port/path
http表示网络协议
content表示本地content provider提供的数据
file表示文件
例如:content://com.google.provider.notepad/notes