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```ts 12import UIAbility from '@ohos.app.ability.UIAbility'; 13 14export default class EntryAbility extends UIAbility { 15 onCreate(want, launchParam) { 16 console.info("EntryAbility onCreate") 17 } 18 onDestroy() { 19 console.info("EntryAbility onDestroy") 20 } 21 onWindowStageCreate(windowStage) { 22 console.info("EntryAbility onWindowStageCreate") 23 windowStage.loadContent('pages/Index', (err, data) => { 24 // ... 25 }); 26 let want = { 27 bundleName: "com.ohos.fa", 28 abilityName: "EntryAbility", 29 }; 30 this.context.startAbility(want).then(() => { 31 console.info('Start Ability successfully.'); 32 }).catch((error) => { 33 console.error("Ability failed: " + JSON.stringify(error)); 34 }); 35 } 36 onWindowStageDestroy() { 37 console.info("EntryAbility onWindowStageDestroy") 38 } 39 onForeground() { 40 console.info("EntryAbility onForeground") 41 } 42 onBackground() { 43 console.info("EntryAbility onBackground") 44 } 45} 46``` 47 48 49## UIAbility Accessing a PageAbility (startAbilityForResult) 50 51Different from **startAbility()**, **startAbilityForResult()** obtains the execution result when the PageAbility is destroyed. 52 53A UIAbility starts a PageAbility through **startAbilityForResult()** in the same way as it starts another UIAbility through **startAbilityForResult()**. 54 55 56```ts 57import UIAbility from '@ohos.app.ability.UIAbility'; 58 59export default class EntryAbility extends UIAbility { 60 onCreate(want, launchParam) { 61 console.info("EntryAbility onCreate") 62 } 63 onDestroy() { 64 console.info("EntryAbility onDestroy") 65 } 66 onWindowStageCreate(windowStage) { 67 console.info("EntryAbility onWindowStageCreate") 68 windowStage.loadContent('pages/Index', (err, data) => { 69 // ... 70 }); 71 let want = { 72 bundleName: "com.ohos.fa", 73 abilityName: "EntryAbility", 74 }; 75 this.context.startAbilityForResult(want).then((result) => { 76 console.info('Ability verify result: ' + JSON.stringify(result)); 77 }).catch((error) => { 78 console.error("Ability failed: " + JSON.stringify(error)); 79 }); 80 } 81 onWindowStageDestroy() { 82 console.info("EntryAbility onWindowStageDestroy") 83 } 84 onForeground() { 85 console.info("EntryAbility onForeground") 86 } 87 onBackground() { 88 console.info("EntryAbility onBackground") 89 } 90} 91``` 92 93 94## ExtensionAbility Starting a PageAbility 95 96The 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. 97 98 99```ts 100import Extension from '@ohos.app.ability.ServiceExtensionAbility' 101 102export default class ServiceExtension extends Extension { 103 onCreate(want) { 104 console.info("ServiceExtension onCreate") 105 } 106 onDestroy() { 107 console.info("ServiceExtension onDestroy") 108 } 109 onRequest(want, startId) { 110 console.info("ServiceExtension onRequest") 111 let wantFA = { 112 bundleName: "com.ohos.fa", 113 abilityName: "EntryAbility", 114 }; 115 this.context.startAbility(wantFA).then(() => { 116 console.info('Start Ability successfully.'); 117 }).catch((error) => { 118 console.error("Ability failed: " + JSON.stringify(error)); 119 }); 120 } 121} 122``` 123