安卓学习笔记(一)显式Intent与隐式Intent
来源:互联网 发布:有线通 知乎 编辑:程序博客网 时间:2024/06/05 15:18
1、显式Intent
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);startActivity(intent);首先构建出了一个Intent,传入FirstActivity.this作为上下文,传入SecondActivity.class作为目标活动,这样我们的“意图”就非常明显了,即在FirstActivity这个活动的基础上打开SecondActivity这个活动。然后通过startActivity()方法来执行这个Intent
2、隐式Intent
需要指定一系列更为抽象的action和category等信息
<activity android:name=".SecondActivity" ><intent-filter><action android:name="com.example.activitytest.ACTION_START" /><category android:name="android.intent.category.DEFAULT" /></intent-filter></activity>在<action>标签中指明了当前活动可以响应com.example.activitytest.ACTION_ START这个action,而<category>标签则包含了一些附加信息,更精确地指明了当前的活动能够响应的Intent中还可能带有的category。
Intent intent = new Intent("com.example.activitytest.ACTION_START");startActivity(intent);与显式一样,需先构建出Intent,然后直接将action中信息传入即可,因为android.intent.category.DEFAULT是一种默认的category,在调用startActivity()方法的时候会自动将这个category添加到Intent中。
其中category属性可以指定多个
<activity android:name=".SecondActivity" ><intent-filter><action android:name="com.example.activitytest.ACTION_START" /><category android:name="android.intent.category.DEFAULT" /> <category android:name="com.example.activitytest.MY_CATEGORY"/><!--自定义的category--></intent-filter></activity>activity中代码如下:
Intent intent = new Intent("com.example.activitytest.ACTION_START");intent.addCategory("com.example.activitytest.MY_CATEGORY");startActivity(intent);创建Intent时的category只要是intent-filter中注册的子集 就会有可能跳转至该活动。
更多的隐式使用方法:
Intent intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://www.baidu.com"));startActivity(intent);Intent.ACTION_VIEW是一个Android系统内置的动作,其常量值为android.intent.action.VIEW。然后通过Uri.parse()方法,将一个网址字符串解析成一个Uri对象,再调用Intent的setData()方法将这个Uri对象传递进去。
<activity android:name=".ThirdActivity" ><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><data android:scheme="http" /></intent-filter></activity>创建第三个活动 然后设置data信息为android:scheme="http" ,这时当启动intent,将会调用到该活动以及其他包含这些信息的程序
0 0
- 安卓学习笔记(一)显式Intent与隐式Intent
- 初识安卓开发之Intent(一)- 显示和隐式Intent
- Intent学习笔记(一)
- 安卓学习: Intent
- 安卓学习(一)——Intent探索
- 安卓学习笔记(二) 使用Intent传递数据
- 安卓学习笔记(三)、使用Intent传递数据
- 安卓学习笔记(五)、使用Intent返回数据
- Intent之学习一(显式与隐式)
- 安卓基础——Intent与Intent Filters(阅读笔记)
- 一、安卓上手(Intent)
- 显式Intent与隐式Intent
- 【Android】显式Intent与隐式Intent
- 显式Intent与隐式Intent
- android学习记录(五)显式Intent与隐式Intent的功能与使用方法解析。
- Intent 笔记(一)
- 安卓学习2-Intent
- Android学习笔记-Intent(一)
- 关于lcm,gcd的一些性质
- error opening trace file: No such file or directory (2)报错原因
- 再见 MongoDB,你好 PostgreSQL
- jsp2的自定义标签
- 01_index 养生
- 安卓学习笔记(一)显式Intent与隐式Intent
- uva 624 (01背包打印路径)
- div+css基础
- hdu 2079
- 使用cocoaPods import导入时没有提示的解决办法
- 01_index_article 养生
- XXX定律
- 抽钻石vs中奖门 概率问题
- 街区最短路径问题