start-uiability-from-fa.md 1.9 KB
Newer Older
Z
zengyawen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# FA模型启动Stage模型UIAbility


本文介绍FA模型的三种应用组件如何启动Stage模型的UIAbility组件。


## PageAbility启动UIAbility

  在PageAbility中启动UIAbility和在PageAbility中启动PageAbility的方式完全相同。

```ts
import featureAbility from '@ohos.ability.featureAbility';

let parameter = {
    "want": {
        bundleName: "com.ohos.stage",
17
        abilityName: "EntryAbility"
Z
zengyawen 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    }
};
featureAbility.startAbility(parameter).then((code) => {
    console.info('Ability verify code: ' + JSON.stringify(code));
}).catch((error) => {
    console.error("Ability failed: " + JSON.stringify(error));
});
```


## PageAbility访问UIAbility(startAbilityForResult)

startAbilityForResult和startAbility的区别是当UIAbility销毁的时候会返回执行结果。

在PageAbility中通过startAbilityForResult启动UIAbility和在PageAbility中通过startAbilityForResult启动PageAbility的方式完全相同。


```ts
import featureAbility from '@ohos.ability.featureAbility';

let parameter = {
    "want": {
        bundleName: "com.ohos.stage",
41
        abilityName: "com.ohos.stage.EntryAbility"
Z
zengyawen 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    }
};
featureAbility.startAbilityForResult(parameter).then((result) => {
    console.info('Ability verify result: ' + JSON.stringify(result));
}).catch((error) => {
    console.error("Ability failed: " + JSON.stringify(error));
});
```


## ServiceAbility/DataAbility启动UIAbility

在ServiceAbility/DataAbility中启动UIAbility和在ServiceAbility/DataAbility中启动PageAbility的方式完全相同。


```ts
import particleAbility from '@ohos.ability.particleAbility';

let parameter = {
    "want": {
        bundleName: "com.ohos.stage",
63
        abilityName: "com.ohos.stage.EntryAbility"
Z
zengyawen 已提交
64 65 66 67 68 69 70 71
    }
};
particleAbility.startAbility(parameter).then(() => {
    console.info('Start Ability successfully.');
}).catch((error) => {
    console.error("Ability failed: " + JSON.stringify(error));
});
```