Android中显式Intent和隐式Intent的区别

1、intent的中文名 称是意图,Intent是各个组件之间信息沟通的桥梁, 既能在Activity之间沟通,又能在Activity与Service之间沟通,也能在Activity与Broadcast之间沟通

   **intent组成元素的列表说明**

2、显式Intent,直接指定来源活动与目标活动,属于精确匹配

1、在Intent的构造函数中指定

java 复制代码
Intent intent = new Intent(this, ActNextActivity.class); // 创建一个目标确定的意图

2、

java 复制代码
Intent intent = new Intent(); // 创建一个新意图
intent.setClass(this, ActNextActivity.class); // 设置意图要跳转的目标活动

3、

java 复制代码
Intent intent = new Intent(); // 创建一个新意图
// 创建包含目标活动在内的组件名称对象
ComponentName component = new ComponentName(this, ActNextActivity.class);
intent.setComponent(component); // 设置意图携带的组件信息

2、隐式intent ,没有明确指定要跳转的目标活动,只给出一个动作字符串让系统自动匹配,属于模糊匹配

一般来讲app都不希望对外部暴露活动的名称,所以先定义好有一个标记串,隐式的Intent便起到了标记过滤作用

调用系统拨号程序的代码例子,其中就用到了隐式intent 和 Uri:

java 复制代码
ActionUriActivity.java


String phoneNo = "12345";
Intent intent = new Intent(); // 创建一个新意图
intent.setAction(Intent.ACTION_DIAL); // 设置意图动作为准备拨号
Uri uri = Uri.parse("tel:" + phoneNo); // 声明一个拨号的Uri
intent.setData(uri); // 设置意图前往的路径
startActivity(intent); // 启动意图通往的活动页面

AndroidManifest.xml中也有intent过滤器的使用

不匹配的过滤,符合条件的优先显示,可以设置默认launcher首页

bash 复制代码
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
相关推荐
勿问东西27 分钟前
【Android】设备操作
android
五味香34 分钟前
C++学习,信号处理
android·c语言·开发语言·c++·学习·算法·信号处理
图王大胜2 小时前
Android Framework AMS(01)AMS启动及相关初始化1-4
android·framework·ams·systemserver
工程师老罗4 小时前
Android Button “No speakable text present” 问题解决
android
小雨cc5566ru5 小时前
hbuilderx+uniapp+Android健身房管理系统 微信小程序z488g
android·微信小程序·uni-app
小雨cc5566ru6 小时前
微信小程序hbuilderx+uniapp+Android 新农村综合风貌旅游展示平台
android·微信小程序·uni-app
小雨cc5566ru6 小时前
小程序 uniapp+Android+hbuilderx体育场地预约管理系统的设计与实现
android·小程序·uni-app
佛系小嘟嘟8 小时前
Android-由switch-case和view.getId()引起的bug:错误:需要常量表达式 的解决办法
android·bug
勿问东西8 小时前
【Android】事件
android
连连斯基11 小时前
Android Framework(八)WMS-窗口动效概述
android·dubbo