#鸿蒙通关秘籍#如何在鸿蒙应用内UIAbility之间获取返回结果?

HarmonyOS
5h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
hm67482bfb05846

要在鸿蒙应用中启动一个UIAbility并希望获取其返回结果,可以按照以下步骤操作:

  1. 使用 startAbilityForResult 来启动目标UIAbility,在 Want 对象中设置必要的参数。

bash import { common, Want } from '@kit.AbilityKit'; const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; let want: Want = { deviceId: '', bundleName: 'com.samples.stagemodelabilitydevelop', moduleName: 'entry', abilityName: 'FuncAbilityA', parameters: { info: '来自EntryAbility UIAbilityComponentsInteractive页面' } }; context.startAbilityForResult(want).then((data) => { // 解析返回结果 let info = data.want?.parameters?.info; });

  1. 在目标UIAbility完成其任务后,调用 terminateSelfWithResult 方法来传递结果。

bash import { common } from '@kit.AbilityKit'; const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; let abilityResult = { resultCode: 1001, want: { bundleName: 'com.samples.stagemodelabilitydevelop', moduleName: 'entry', abilityName: 'FuncAbilityB', parameters: { info: '来自FuncAbility Index页面' }, }, }; context.terminateSelfWithResult(abilityResult);


分享
微博
QQ
微信
回复
3h前
相关问题