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';
13import Want from '@ohos.app.ability.Want';
14import { BusinessError } from '@ohos.base';
15import hilog from '@ohos.hilog';
16
17const TAG: string = 'PageInterflowFaAndStage';
18
19const domain: number = 0xFF00;
20
21@Entry
22@Component
23struct PageInterflowFaAndStage {
24  build() {
25    Column() {
26      //...
27      List({ initialIndex: 0 }) {
28        ListItem() {
29          Row() {
30            //...
31          }
32          .onClick(() => {
33            let want: Want = {
34              bundleName: 'ohos.samples.etsclock',
35              abilityName: 'MainAbility'
36            };
37            featureAbility.startAbility({ want }).then((code) => {
38              hilog.info(domain, TAG, 'Ability verify code: ' + JSON.stringify(code));
39            }).catch((error: BusinessError) => {
40              hilog.error(domain, TAG, 'Ability failed: ' + JSON.stringify(error));
41            });
42            //...
43          })
44        }
45        //...
46      }
47      //...
48    }
49    //...
50  }
51}
52```
53
54
55## PageAbility访问UIAbility(startAbilityForResult)
56
57startAbilityForResult和startAbility的区别是当UIAbility销毁的时候会返回执行结果。
58
59在PageAbility中通过startAbilityForResult启动UIAbility和在PageAbility中通过startAbilityForResult启动PageAbility的方式完全相同。
60
61
62```ts
63import featureAbility from '@ohos.ability.featureAbility';
64import Want from '@ohos.app.ability.Want';
65import { BusinessError } from '@ohos.base';
66import hilog from '@ohos.hilog';
67
68const TAG: string = 'PageInterflowFaAndStage';
69
70const domain: number = 0xFF00;
71
72@Entry
73@Component
74struct PageInterflowFaAndStage {
75  build() {
76    Column() {
77      //...
78      List({ initialIndex: 0 }) {
79        ListItem() {
80          Row() {
81            //...
82          }
83          .onClick(() => {
84            let want: Want = {
85              bundleName: 'ohos.samples.etsclock',
86              abilityName: 'MainAbility'
87            };
88            featureAbility.startAbilityForResult({ want }).then((result) => {
89              hilog.info(domain, TAG, 'Ability verify result: ' + JSON.stringify(result));
90            }).catch((error: BusinessError) => {
91              hilog.error(domain, TAG, 'Ability failed: ' + JSON.stringify(error));
92            });
93          })
94        }
95        //...
96      }
97      //...
98    }
99    //...
100  }
101}
102```
103
104
105## ServiceAbility/DataAbility启动UIAbility
106
107ServiceAbility/DataAbility中启动UIAbility和在ServiceAbility/DataAbility中启动PageAbility的方式完全相同。
108
109
110```ts
111import type common from '@ohos.app.ability.common';
112import particleAbility from '@ohos.ability.particleAbility';
113import type Want from '@ohos.app.ability.Want';
114import type { BusinessError } from '@ohos.base';
115import hilog from '@ohos.hilog';
116
117const TAG: string = '[Sample_FAModelAbilityDevelop]';
118
119const domain: number = 0xFF00;
120
121class ServiceAbilityStartUiAbility {
122  onStart(): void {
123    // 启动UIAbility
124    let want: Want = {
125      bundleName: 'ohos.samples.etsclock',
126      abilityName: 'MainAbility'
127    };
128    particleAbility.startAbility({ want }).then(() => {
129      hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility Start Ability successfully.');
130    }).catch((error: BusinessError) => {
131      hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility Ability failed: ' + JSON.stringify(error));
132    });
133  }
134};
135
136export default new ServiceAbilityStartUiAbility();
137```
138