1# Starting a UIAbility from the FA Model 2 3 4This topic describes how the three application components of the FA model start the UIAbility component of the stage model. 5 6 7## PageAbility Starting a UIAbility 8 9A PageAbility starts a UIAbility in the same way as it starts another 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 Accessing a UIAbility (startAbilityForResult) 56 57Different from **startAbility()**, **startAbilityForResult()** obtains the execution result when the UIAbility is destroyed. 58 59A PageAbility starts a UIAbility through **startAbilityForResult()** in the same way as it starts another PageAbility through **startAbilityForResult()**. 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 or DataAbility Starting a UIAbility 106 107A ServiceAbility or DataAbility starts a UIAbility in the same way as it starts a 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 // Start the 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