• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 启动本地PageAbility
2
3
4PageAbility相关的能力通过featureAbility提供,启动本地Ability通过featureAbility中的startAbility接口实现。
5
6
7  **表1** featureAbility接口说明
8
9| 接口名 | 接口描述 |
10| -------- | -------- |
11| startAbility(parameter: StartAbilityParameter) | 启动Ability。 |
12| startAbilityForResult(parameter: StartAbilityParameter) | 启动Ability,并在该Ability被销毁时返回执行结果。 |
13
14
15如下示例通过startAbility显式启动PageAbility。启动Ability的参数包含want,关于want的说明详见[对象间信息传递载体Want](want-fa.md),相应的,隐式启动与显式启动也不在此赘述。
16
17```ts
18import featureAbility from '@ohos.ability.featureAbility'
19(async () => {
20  try {
21    console.info('Begin to start ability')
22    let param = {
23      want: {
24        bundleName: "com.example.myapplication",
25        moduleName: "entry",
26        abilityName: "com.example.myapplication.EntryAbility"
27      }
28    }
29    await featureAbility.startAbility(param)
30    console.info(`Start ability succeed`)
31  }
32  catch (error) {
33    console.error('Start ability failed with ' + error)
34  }
35})()
36```
37