harmony 鸿蒙启动本地PageAbility

  • 2022-12-13
  • 浏览 (654)

启动本地PageAbility

PageAbility相关的能力通过featureAbility提供,启动本地Ability通过featureAbility中的startAbility接口实现。

表1 featureAbility接口说明

接口名 接口描述
startAbility(parameter: StartAbilityParameter) 启动Ability。
startAbilityForResult(parameter: StartAbilityParameter) 启动Ability,并在该Ability被销毁时返回执行结果。

如下示例通过startAbility显式启动PageAbility。启动Ability的参数包含want,关于want的说明详见对象间信息传递载体Want,相应的,隐式启动与显式启动也不在此赘述。

import featureAbility from '@ohos.ability.featureAbility'
import Want from '@ohos.app.ability.Want';

(async () => {
  try {
    console.info('Begin to start ability')
    let want: Want = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      abilityName: "com.example.myapplication.EntryAbility"
    }
    await featureAbility.startAbility({want})
    console.info(`Start ability succeed`)
  } 
  catch (error) {
    console.error('Start ability failed with ' + error)
  }
})()

你可能感兴趣的鸿蒙文章

harmony 鸿蒙应用模型

harmony 鸿蒙使用显式Want启动应用组件

harmony 鸿蒙使用隐式Want打开网址

harmony 鸿蒙AbilityStage组件容器

harmony 鸿蒙访问DataAbility

harmony 鸿蒙FA模型访问Stage模型DataShareExtensionAbility

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙常见action与entities

harmony 鸿蒙API切换概述

harmony 鸿蒙app和deviceConfig的切换

0  赞