HarmonyOS中 specified 启动模式的工作原理与 Key 匹配机制?#智解鸿蒙
harmonyos鸿蒙鸿蒙问答专区
specified 模式如何通过 Key 值匹配或创建 UIAbility 实例
您需要先 登录 才能评论/回答
全部评论(1)
-
调用方在
Want.parameters中设置唯一 instanceKey 作为标识。 -
系统拉起目标 UIAbility 前,会进入其 AbilityStage 的
onAcceptWant() 回调,从中返回形如SpecifiedAbilityInstance_${instanceKey}的 Key。 -
系统根据该 Key 匹配已有实例:
-
匹配成功 → 启动原实例,触发
onNewWant(),不触发onCreate()/onWindowStageCreate()。 -
匹配失败 → 创建新实例,触发
onCreate()与onWindowStageCreate()。配置方式:在目标 UIAbility 的
module.json5中设launchType为"specified",并在 AbilityStage 中实现onAcceptWant()逻辑。
-
2025-12-19 08:28:37