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>
相关推荐
技术liul27 分钟前
使用安卓平板,通过USB数据线(而不是Wi-Fi)来控制电脑(版本1)
android·stm32·电脑
_祝你今天愉快2 小时前
Android FrameWork - 开机启动 & Init 进程 初探
android
2501_916007472 小时前
iOS App 上架实战 从内测到应用商店发布的全周期流程解析
android·ios·小程序·https·uni-app·iphone·webview
TimeFine3 小时前
Android 邮件发送日志
android
杨过过儿3 小时前
【Task02】:四步构建简单rag(第一章3节)
android·java·数据库
Wgllss3 小时前
Kotlin 享元设计模式详解 和对象池及在内存优化中的几种案例和应用场景
android·架构·android jetpack
zzywxc7875 小时前
AI 行业应用:金融、医疗、教育、制造业领域的落地案例与技术实现
android·前端·人工智能·chrome·金融·rxjava
sTone873755 小时前
android studio之外使用NDK编译生成android指定架构的动态库
android·c++
胖虎16 小时前
Android 入门到实战(三):ViewPager及ViewPager2多页面布局
android·viewpager·viewpager2
风往哪边走8 小时前
Media3在线本地视频播放器
android