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>
相关推荐
JMchen1231 小时前
Android后台服务与网络保活:WorkManager的实战应用
android·java·网络·kotlin·php·android-studio
crmscs2 小时前
剪映永久解锁版/电脑版永久会员VIP/安卓SVIP手机永久版下载
android·智能手机·电脑
localbob2 小时前
杀戮尖塔 v6 MOD整合版(Slay the Spire)安卓+PC端免安装中文版分享 卡牌肉鸽神作!杀戮尖塔中文版,电脑和手机都能玩!杀戮尖塔.exe 杀戮尖塔.apk
android·杀戮尖塔apk·杀戮尖塔exe·游戏分享
机建狂魔2 小时前
手机秒变电影机:Blackmagic Camera + LUT滤镜包的专业级视频解决方案
android·拍照·摄影·lut滤镜·拍摄·摄像·录像
hudawei9962 小时前
flutter和Android动画的对比
android·flutter·动画
lxysbly4 小时前
md模拟器安卓版带金手指2026
android
儿歌八万首5 小时前
硬核春节:用 Compose 打造“赛博鞭炮”
android·kotlin·compose·春节
消失的旧时光-19437 小时前
从 Kotlin 到 Dart:为什么 sealed 是处理「多种返回结果」的最佳方式?
android·开发语言·flutter·架构·kotlin·sealed
Jinkxs8 小时前
Gradle - 与Groovy/Kotlin DSL对比 构建脚本语言选择指南
android·开发语言·kotlin
&有梦想的咸鱼&8 小时前
Kotlin委托机制的底层实现深度解析(74)
android·开发语言·kotlin