• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# FA模型启动Stage模型UIAbility
2
3
4本文介绍FA模型的三种应用组件如何启动Stage模型的UIAbility组件。
5
6
7## PageAbility启动UIAbility
8
9  在PageAbility中启动UIAbility和在PageAbility中启动PageAbility的方式完全相同。
10
11```ts
12import featureAbility from '@ohos.ability.featureAbility';
13
14let parameter = {
15    "want": {
16        bundleName: "com.ohos.stage",
17        abilityName: "com.ohos.stage.EntryAbility"
18    }
19};
20featureAbility.startAbility(parameter).then((code) => {
21    console.info('Ability verify code: ' + JSON.stringify(code));
22}).catch((error) => {
23    console.error("Ability failed: " + JSON.stringify(error));
24});
25```
26
27
28## PageAbility访问UIAbility(startAbilityForResult)
29
30startAbilityForResult和startAbility的区别是当UIAbility销毁的时候会返回执行结果。
31
32在PageAbility中通过startAbilityForResult启动UIAbility和在PageAbility中通过startAbilityForResult启动PageAbility的方式完全相同。
33
34
35```ts
36import featureAbility from '@ohos.ability.featureAbility';
37
38let parameter = {
39    "want": {
40        bundleName: "com.ohos.stage",
41        abilityName: "com.ohos.stage.EntryAbility"
42    }
43};
44featureAbility.startAbilityForResult(parameter).then((result) => {
45    console.info('Ability verify result: ' + JSON.stringify(result));
46}).catch((error) => {
47    console.error("Ability failed: " + JSON.stringify(error));
48});
49```
50
51
52## ServiceAbility/DataAbility启动UIAbility
53
54ServiceAbility/DataAbility中启动UIAbility和在ServiceAbility/DataAbility中启动PageAbility的方式完全相同。
55
56
57```ts
58import particleAbility from '@ohos.ability.particleAbility';
59
60let parameter = {
61    "want": {
62        bundleName: "com.ohos.stage",
63        abilityName: "com.ohos.stage.EntryAbility"
64    }
65};
66particleAbility.startAbility(parameter).then(() => {
67    console.info('Start Ability successfully.');
68}).catch((error) => {
69    console.error("Ability failed: " + JSON.stringify(error));
70});
71```
72