1# Starting a PageAbility from the Stage Model 2 3 4This topic describes how the two application components of the stage model start the PageAbility component of the FA model. 5 6 7## UIAbility Starting a PageAbility 8 9A UIAbility starts a PageAbility in the same way as it starts another UIAbility. 10 11> **NOTE** 12> 13> In the FA model, **abilityName** consists of **bundleName** and **AbilityName**. For details, see the code snippet below. 14 15```ts 16import UIAbility from '@ohos.app.ability.UIAbility'; 17 18export default class EntryAbility extends UIAbility { 19 onCreate(want, launchParam) { 20 console.info("EntryAbility onCreate") 21 } 22 onDestroy() { 23 console.info("EntryAbility onDestroy") 24 } 25 onWindowStageCreate(windowStage) { 26 console.info("EntryAbility onWindowStageCreate") 27 windowStage.loadContent('pages/Index', (err, data) => { 28 ... 29 }); 30 let want = { 31 bundleName: "com.ohos.fa", 32 abilityName: "com.ohos.fa.EntryAbility", 33 }; 34 this.context.startAbility(want).then(() => { 35 console.info('Start Ability successfully.'); 36 }).catch((error) => { 37 console.error("Ability failed: " + JSON.stringify(error)); 38 }); 39 } 40 onWindowStageDestroy() { 41 console.info("EntryAbility onWindowStageDestroy") 42 } 43 onForeground() { 44 console.info("EntryAbility onForeground") 45 } 46 onBackground() { 47 console.info("EntryAbility onBackground") 48 } 49} 50``` 51 52 53## UIAbility Accessing a PageAbility (startAbilityForResult) 54 55Different from **startAbility()**, **startAbilityForResult()** obtains the execution result when the PageAbility is destroyed. 56 57A UIAbility starts a PageAbility through **startAbilityForResult()** in the same way as it starts another UIAbility through **startAbilityForResult()**. 58 59 60```ts 61import UIAbility from '@ohos.app.ability.UIAbility'; 62 63export default class EntryAbility extends UIAbility { 64 onCreate(want, launchParam) { 65 console.info("EntryAbility onCreate") 66 } 67 onDestroy() { 68 console.info("EntryAbility onDestroy") 69 } 70 onWindowStageCreate(windowStage) { 71 console.info("EntryAbility onWindowStageCreate") 72 windowStage.loadContent('pages/Index', (err, data) => { 73 ... 74 }); 75 let want = { 76 bundleName: "com.ohos.fa", 77 abilityName: "EntryAbility", 78 }; 79 this.context.startAbilityForResult(want).then((result) => { 80 console.info('Ability verify result: ' + JSON.stringify(result)); 81 }).catch((error) => { 82 console.error("Ability failed: " + JSON.stringify(error)); 83 }); 84 } 85 onWindowStageDestroy() { 86 console.info("EntryAbility onWindowStageDestroy") 87 } 88 onForeground() { 89 console.info("EntryAbility onForeground") 90 } 91 onBackground() { 92 console.info("EntryAbility onBackground") 93 } 94} 95``` 96 97 98## ExtensionAbility Starting a PageAbility 99 100The following uses the ServiceExtensionAbility component as an example to describe how an ExtensionAbility starts a PageAbility. A ServiceExtensionAbility starts a PageAbility in the same way as it starts a UIAbility. 101 102 103```ts 104import Extension from '@ohos.app.ability.ServiceExtensionAbility' 105 106export default class ServiceExtension extends Extension { 107 onCreate(want) { 108 console.info("ServiceExtension onCreate") 109 } 110 onDestroy() { 111 console.info("ServiceExtension onDestroy") 112 } 113 onRequest(want, startId) { 114 console.info("ServiceExtension onRequest") 115 let wantFA = { 116 bundleName: "com.ohos.fa", 117 abilityName: "EntryAbility", 118 }; 119 this.context.startAbility(wantFA).then(() => { 120 console.info('Start Ability successfully.'); 121 }).catch((error) => { 122 console.error("Ability failed: " + JSON.stringify(error)); 123 }); 124 } 125} 126``` 127