android Intent
来源:互联网 发布:网络综艺点击量 编辑:程序博客网 时间:2024/05/17 01:10
什么是Intent?
答:是执行某操作的一个抽象描述.
Android基本的设计理念是鼓励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了一种通用的消息系统,它允许在你的应用程序与其它的应用程序间传递Intent来执行动作和产生事件。
使用Intent可以激活Android应用的三个核心组件:活动、服务和广播接收器。
Intent可以划分成显式意图和隐式意图。
显式意图:调用Intent.setComponent()或Intent.setClass()方法明确指定了组件名的Intent为显式意图,显式意图明确指定了Intent应该传递给哪个组件。
隐式意图:没有明确指定组件名的Intent为隐式意图。 Android系统会根据隐式意图中设置的动作(action)、类别(category)、数据(URI和数据类型)找到最合适的组件来处理这个意图。
demo:
<intent-filter> <action android:name="android.intent.action.CALL" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="tel" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.CALL" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.item/phone" /> </intent-filter>
作用?
答:解决Android应用的各项组件之间的通讯。
如何为Intent附加数据?
答:两种做法。
1、用于批量添加数据到Intent:
Intent intent = new Intent();
Bundle bundle = new Bundle();//该类用作携带数据
bundle.putString("name", "教育");
intent.putExtras(bundle);//为意图追加额外的数据,意图原来已经具有的数据不会丢失,但key同名的数据会被替换
2、这种写法的作用等价于上面的写法,只不过这种写法是把数据一个个地添加进Intent,这种写法使用起来比较方便,而且只需要编写少量的代码。
Intent intent = new Intent();
intent.putExtra("name", "教育");
注:
Intent提供了各种常用类型重载后的putExtra()方法,如: putExtra(String name, String value)、 putExtra(String name, long value),
在putExtra()方法内部会判断当前Intent对象内部是否已经存在一个Bundle对象,如果不存在就会新建Bundle对象,以后调用putExtra()方法传入的值都会存放于该Bundle对象。
- Android intent intent-filter
- Android intent intent-filter
- Android intent intent-filter
- Android intent
- Android Intent
- Android Intent
- android Intent
- android intent
- android intent
- android intent
- Android------Intent
- android Intent
- Android Intent
- android intent
- Android Intent
- android intent
- Android Intent
- android --------intent
- 当小米遇上“泄密门”,用户隐私谁来保护???
- jquery水平滑动tab选项卡
- [Python]webservice 学习(1) -- 简单服务和调用
- hdu 1864(最大报销额)——01背包
- opencV源码分析之HOG
- android Intent
- 区别adb logcat 与 adb logcat -b main
- Android Intent传递对象小结
- libgdx的目录结构 以及常见接口
- 实战--积分投票系统血泪教训
- throw和throw ex的区别
- 求属性集的闭包和函数依赖的闭包算法(二)
- WinSock实现的大文件传输
- 用Bitblaze进行程序分析之二------TEMU的配置和使用