Android中Intent介绍
2016-06-15 20:59
501 查看
Android中Intent主要分为显式Intent和隐式Intent,今天会主要讲隐式Intent
一、显式Intent
最常用的就是下面这种形式
二、隐式Intent
这种Intent方式主要是通过action和category来由系统分析该启动哪一个活动
1、指定action
AndroidManifest.xml中
只有指定的action和category同时匹配才会响应该活动,上面的代码在启动时之所以没有指定category是因为android.intent.category.DEFAULT是一直默认的category,会在startActivity时默认杯添加到intent中。
2、指定action和category
3、启动其他程序的活动
上面的代码会调用浏览器打开http://www.qq.com
4、在标签中配置data标签
data标签中主要可以配置以下内容
android:scheme 用来指定数据的协议部分
android:host 用于指定数据的主机名部分
android:port 指定数据的端口
android:path 指定主机名和端口之后的部分
android:mimeType 指定可以处理的数据类型,可以使用通配符
常用的数据协议
- http协议
- geo 地理位置
- tel 拨打电话
一、显式Intent
最常用的就是下面这种形式
Intent intent = new Intent(FirstActivity.this, Second.class); startActivity(intent);
二、隐式Intent
这种Intent方式主要是通过action和category来由系统分析该启动哪一个活动
1、指定action
AndroidManifest.xml中
<activity android:name=".WelcomeActivity"> <intent-filter> <action android:name="com.bingjian.ACTION_START" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Intent intent = new Intent("com.bingjian.ACTION_START"); startActivity(intent);
只有指定的action和category同时匹配才会响应该活动,上面的代码在启动时之所以没有指定category是因为android.intent.category.DEFAULT是一直默认的category,会在startActivity时默认杯添加到intent中。
2、指定action和category
<activity android:name=".WelcomeActivity"> <intent-filter> <action android:name="com.bingjian.ACTION_START" /> <category android:name="com.bingjian.MY_CATEGORY" /> </intent-filter> </activity>
Intent intent = new Intent("com.bingjian.ACTION_START"); intent.addCategory("com.bingjian.MY_CATEGORY"); startActivity(intent);
3、启动其他程序的活动
Intent intent = new Intent("Intent.ACTION_VIEW"); intent.setData(Uri.parse("http://www.qq.com")); startActivity(intent);
上面的代码会调用浏览器打开http://www.qq.com
4、在标签中配置data标签
data标签中主要可以配置以下内容
android:scheme 用来指定数据的协议部分
android:host 用于指定数据的主机名部分
android:port 指定数据的端口
android:path 指定主机名和端口之后的部分
android:mimeType 指定可以处理的数据类型,可以使用通配符
常用的数据协议
- http协议
- geo 地理位置
- tel 拨打电话
相关文章推荐
- android进程重启及activity恢复
- Android之BroadcastReceiver(二):接收系统广播
- Android JAVA中去掉字符串空格的方法
- Android天气预报开发
- Android Studio使用gradle-retrolambda支持Java8 新特性 Lambde表达式
- Android拨打电话
- Android开发学习笔记之通过API接口将LaTex数学函数表达式转化为图片形式
- android Fragment 源码分析
- 深入理解Android的startservice和bindservice
- 我的第一个Android程序--HelloWorld
- Android中的dex分包
- Android Studio提示忽略大小写
- Android之三种Menu的使用与分析
- Android之Activity
- Android 5.1系统动画的调节
- [Android Studio] Android studio 多渠道打包(超简洁版)
- Android Studio自动提取控件Style样式
- Android studio 配置忽略
- 责任链模式在Android中的应用
- Android--自定义弹出框-自定义dialog