#鸿蒙通关秘籍#如何在鸿蒙应用中启动应用内的UIAbility?

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

在鸿蒙应用中如需启动应用内的UIAbility,可通过如下步骤:

  1. 在启动UIAbility的代码中使用 startAbility 方法,并传入 Want 对象作为参数。 Want 对象中需指定 bundleNameabilityName

bash import { common, Want } from '@kit.AbilityKit'; const context = getContext(this) as common.UIAbilityContext; let wantInfo: Want = { deviceId: '', bundleName: 'com.samples.stagemodelabilitydevelop', moduleName: 'entry', abilityName: 'FuncAbilityA', parameters: { info: '来自EntryAbility Page_UIAbilityComponentsInteractive页面' }, }; context.startAbility(wantInfo);

  1. 在被启动的UIAbility中,通过 onCreateonNewWant 方法接收参数。

bash import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; export default class FuncAbilityA extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { let info = want.parameters?.info; } }

  1. 业务完成后,调用 terminateSelf 方法关闭当前UIAbility。

bash import { common } from '@kit.AbilityKit'; const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; context.terminateSelf();


分享
微博
QQ
微信
回复
4h前
相关问题
如何实现设备应用UIAbility跳转
2127浏览 • 1回复 待解决