您的位置:首页 > 新闻 > 热点要闻 > 爱站工具包的主要功能_seo优化教程视频_2022知名品牌营销案例100例_中文搜索引擎排名

爱站工具包的主要功能_seo优化教程视频_2022知名品牌营销案例100例_中文搜索引擎排名

2025/4/18 10:21:21 来源:https://blog.csdn.net/xdf0101/article/details/147104249  浏览:    关键词:爱站工具包的主要功能_seo优化教程视频_2022知名品牌营销案例100例_中文搜索引擎排名
爱站工具包的主要功能_seo优化教程视频_2022知名品牌营销案例100例_中文搜索引擎排名

在回答 Intent 问题时,清晰区分其 定义类型 和 应用场景。以下是的回答策略:


一、Intent 的核心定义

Intent 是 Android 系统中的 消息传递对象,主要用于三大场景:

2. 隐式 Intent(Implicit Intent)


三、Intent 的关键组成要素

属性作用示例值
Component显式指定目标组件ComponentName(pkg, cls)
Action描述操作类型(常量)Intent.ACTION_VIEW
Category补充Action的上下文信息Intent.CATEGORY_BROWSABLE
DataURI格式的数据(通常与Type配合)Uri.parse("http://example.com")
TypeMIME类型"image/png"
Extras附加数据的BundleputExtra("id", 123)
Flags控制启动模式FLAG_ACTIVITY_CLEAR_TOP

四、高级使用场景

1. PendingIntent

2. 深度链接(Deep Link)

3. Intent 过滤器冲突解决

当多个 Activity 声明相同 <intent-filter> 时:


五、面试高频问

  1. 组件间通信:启动 Activity/Service,发送广播

  2. 数据传递:携带附加数据(Bundle)

  3. 隐式调用:声明式匹配系统或第三方组件

    二、Intent 的两种核心类型

  4. 1. 显式 Intent(Explicit Intent)

  5. 特点:明确指定目标组件(类名)

  6. 使用场景:应用内部组件跳转

  7. 优势:高效直接,无需系统解析

  8. 示例

    kotlin

    复制

    // 启动Service
    Intent(this, MyService::class.java).also { startService(it)
    }
  9. 特点:通过 Action、Category、Data 等属性匹配组件

  10. 使用场景:跨应用调用(如分享、打开链接)

  11. 匹配规则

    xml

    复制

    <!-- AndroidManifest.xml 声明 -->
    <activity android:name=".ShareActivity"><intent-filter><action android:name="android.intent.action.SEND" /><category android:name="android.intent.category.DEFAULT" /><data android:mimeType="text/plain" /></intent-filter>
    </activity>

    运行 HTML

  12. 示例

    kotlin

    复制

    // 调用系统分享
    Intent(Intent.ACTION_SEND).apply {type = "text/plain"putExtra(Intent.EXTRA_TEXT, "分享内容")startActivity(Intent.createChooser(this, "选择分享应用"))
    }
  13. 特点:允许外部应用以当前应用身份执行 Intent

  14. 应用场景:通知栏点击、AlarmManager

  15. 配置

    xml

    复制

    <intent-filter><data android:scheme="https" android:host="example.com" android:pathPrefix="/detail"/><!-- 必须添加 --><category android:name="android.intent.category.BROWSABLE"/><category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

    运行 HTML

  16. 验证

    bash

    复制

    adb shell am start -W -a android.intent.action.VIEW -d "https://example.com/detail?id=123"
  17. 系统弹出选择器(ResolverActivity)

  18. 可通过 PackageManager.queryIntentActivities() 获取匹配列表

  19. 优先选择优先级高的组件(<intent-filter android:priority="100">

  20. 示例

    kotlin

    复制

    val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
    )

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com