博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Intent
阅读量:4600 次
发布时间:2019-06-09

本文共 1290 字,大约阅读时间需要 4 分钟。

Android基本的设计理念是鼓励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了一种通用的消息系统,它允许在你的应用程序与其它的应用程序间传递Intent来执行动作和产生事件。使用Intent可以激活Android应用的三个核心组件:活动、服务和广播接收器。
Intent可以划分成显式意图和隐式意图。
显式意图:调用Intent.setComponent()或Intent.setClass()方法指定了组件名或类对象的Intent为显式意图,显式意图明确指定了Intent应该传递给哪个组件。
隐式意图:没有调用Intent.setComponent()或Intent.setClass()方法指定组件名或类对象的Intent为隐式意图。 Android系统会根据隐式意图中设置的动作(action)、类别(category)、数据(URI和数据类型)找到最合适的组件来处理这个意图。那么Android是怎样寻找到这个最合适的组件呢?记的前面我们在定义活动时,指定了一个intent-filter,Intent Filter(过滤器)其实就是用来匹配隐式Intent的,如果Intent Filter定义的动作、类别、数据(URI和数据类型)与Intent匹配,就会使用Intent Filter所在的组件来处理该Intent。想要接收使用startActivity()方法传递的隐式意图的活动必须在它们的意图过滤器中包含"android.intent.category.DEFAULT"
A、意图配置文件
               <activity android:name=".OtherActivity" android:label="其他意图">
                        <intent-filter>
                                <action android:name="com.tjp.intent.action.other" />
                                <category android:name="android.intent.category.DEFAULT" />  
                                <data android:scheme="content" android:host=" " android:path="/person" android:mimeType="jpg" />
                                <category android:name="android.intent.category.DEFAULT" />
                        </intent-filter>
                </activity>
B、调用隐式意图
                Intent intent=new Intent("com.tjp.intent.action.other");
                intent.setDataAndType(Uri.parse("content://www.tjp.com/person"), "jpg");//设置数据和类型
                startActivity(intent);

转载于:https://www.cnblogs.com/tjpfly/archive/2011/05/28/Intent.html

你可能感兴趣的文章
TTL电平,CMOS电平,OC门,OD门基础知识
查看>>
JavaScript面试题
查看>>
[转帖]架构师眼中的高并发架构
查看>>
ios的一些开源资源
查看>>
beego——session模块
查看>>
NHibernate.3.0.Cookbook第一章第8节的翻译
查看>>
西瓜书第1章习题
查看>>
反卷积Deconvolution
查看>>
su - user解释
查看>>
验证文本框输入内容类型是汉字
查看>>
线程通信,生产者消费者问题(Java)
查看>>
责任链模式
查看>>
解决Windows7 Update无法检查更新
查看>>
Python爬虫基础
查看>>
Liferay7 BPM门户开发之2: BPMN 2.0 规范入门 (Activiti BPMN extensions)
查看>>
深入研究mysql中group by与order by取分类最新时间内容——同理在android里也可用
查看>>
用JS掃描用戶的mouse和健盤,如果15分鍾不操作就退出
查看>>
“The Complete Reference C"读书笔记
查看>>
浅析条件竞争
查看>>
初学Java
查看>>