1# @ohos.app.ability.EmbeddedUIExtensionAbility (ExtensionAbilities for Embedded UIs Across Processes) 2 3**EmbeddedUIExtensionAbility**, inherited from [UIExtensionAbility](js-apis-app-ability-uiExtensionAbility.md), provides ExtensionAbilities for the embedded UI across processes. Currently, the EmbeddedUIExtensionAbility can be started only by the UIAbility of the same application and can be used only in scenarios with multi-process permissions. For details about the inheritance relationship of each ability, see [Inheritance Relationship](./js-apis-app-ability-ability.md#ability-inheritance-relationship). 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs of this module can be used only in the stage model. 10 11## Modules to Import 12 13```ts 14import { EmbeddedUIExtensionAbility } from '@kit.AbilityKit'; 15``` 16 17## Properties 18 19**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 20 21| Name| Type| Read-only| Mandatory| Description| 22| -------- | -------- | -------- | -------- | -------- | 23| context | [UIExtensionContext](js-apis-inner-application-uiExtensionContext.md) | No| No| Context of the ExtensionAbility.| 24 25## EmbeddedUIExtensionAbility.onCreate 26 27onCreate(): void 28 29Called to initialize the service logic when an EmbeddedUIExtensionAbility is created. 30 31**System capability**: SystemCapability.Ability.AbilityRuntime.Core 32 33**Example** 34 35 ```ts 36 import { EmbeddedUIExtensionAbility } from '@kit.AbilityKit'; 37 38 const TAG: string = '[testTag] EmbeddedUIExt'; 39 40 export default class EmbeddedUIExt extends EmbeddedUIExtensionAbility { 41 onCreate() { 42 console.info(TAG, `onCreate`); 43 } 44 } 45 ``` 46 47## EmbeddedUIExtensionAbility.onSessionCreate 48 49onSessionCreate(want: Want, session: UIExtensionContentSession): void 50 51Called when a **UIExtensionContentSession** instance is created for this EmbeddedUIExtensionAbility. 52 53**System capability**: SystemCapability.Ability.AbilityRuntime.Core 54 55**Parameters** 56 57| Name| Type| Mandatory| Description| 58| -------- | -------- | -------- | -------- | 59| want | [Want](js-apis-app-ability-want.md) | Yes| Want information of the EmbeddedUIExtensionAbility, including the ability name and bundle name.| 60| session | [UIExtensionContentSession](js-apis-app-ability-uiExtensionContentSession.md) | Yes| UI content information related to the EmbeddedUIExtensionAbility.| 61 62**Example** 63 64 ```ts 65 import { EmbeddedUIExtensionAbility, Want, UIExtensionContentSession } from '@kit.AbilityKit'; 66 67 const TAG: string = '[testTag] EmbeddedUIExt'; 68 69 export default class EmbeddedUIExt extends EmbeddedUIExtensionAbility { 70 onSessionCreate(want: Want, session: UIExtensionContentSession) { 71 console.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`); 72 } 73 } 74 ``` 75 76## EmbeddedUIExtensionAbility.onSessionDestroy 77 78onSessionDestroy(session: UIExtensionContentSession): void 79 80Called when a **UIExtensionContentSession** instance is destroyed for this EmbeddedUIExtensionAbility. 81 82**System capability**: SystemCapability.Ability.AbilityRuntime.Core 83 84**Parameters** 85 86| Name| Type| Mandatory| Description| 87| -------- | -------- | -------- | -------- | 88| session | [UIExtensionContentSession](js-apis-app-ability-uiExtensionContentSession.md) | Yes| UI content information related to the EmbeddedUIExtensionAbility.| 89 90**Example** 91 92 ```ts 93 import { EmbeddedUIExtensionAbility, UIExtensionContentSession } from '@kit.AbilityKit'; 94 95 const TAG: string = '[testTag] EmbeddedUIExt'; 96 97 export default class EmbeddedUIExt extends EmbeddedUIExtensionAbility { 98 onSessionDestroy(session: UIExtensionContentSession) { 99 console.info(TAG, `onSessionDestroy`); 100 } 101 } 102 ``` 103 104## EmbeddedUIExtensionAbility.onForeground 105 106onForeground(): void 107 108Called when this EmbeddedUIExtensionAbility is switched from the background to the foreground. 109 110**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 111 112**Example** 113 114 ```ts 115 import { EmbeddedUIExtensionAbility } from '@kit.AbilityKit'; 116 117 const TAG: string = '[testTag] EmbeddedUIExt'; 118 119 export default class EmbeddedUIExt extends EmbeddedUIExtensionAbility { 120 onForeground() { 121 console.info(TAG, `onForeground`); 122 } 123 } 124 ``` 125 126## EmbeddedUIExtensionAbility.onBackground 127 128onBackground(): void 129 130Called when this EmbeddedUIExtensionAbility is switched from the foreground to the background. 131 132**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 133 134**Example** 135 136 ```ts 137 import { EmbeddedUIExtensionAbility } from '@kit.AbilityKit'; 138 139 const TAG: string = '[testTag] EmbeddedUIExt'; 140 141 export default class EmbeddedUIExt extends EmbeddedUIExtensionAbility { 142 onBackground() { 143 console.info(TAG, `onBackground`); 144 } 145 } 146 ``` 147 148## EmbeddedUIExtensionAbility.onDestroy 149 150onDestroy(): void | Promise<void> 151 152Called to clear resources when this EmbeddedUIExtensionAbility is destroyed. 153After the **onDestroy()** lifecycle callback is executed, the application may exit. Consequently, the asynchronous function (for example, asynchronously writing data to the database) in **onDestroy()** may fail to be executed. You can use the asynchronous lifecycle to ensure that the subsequent lifecycle continues only after the asynchronous function in **onDestroy()** finishes the execution. 154 155**System capability**: SystemCapability.Ability.AbilityRuntime.Core 156 157**Returns** 158 159| Type | Description | 160| ----------------- | ------------------------------------------------------------ | 161| void \| Promise\<void> | No return value or a Promise object that returns no value. | 162 163**Example** 164 165 ```ts 166 import { EmbeddedUIExtensionAbility } from '@kit.AbilityKit'; 167 168 const TAG: string = '[testTag] EmbeddedUIExt'; 169 170 export default class EmbeddedUIExt extends EmbeddedUIExtensionAbility { 171 onDestroy() { 172 console.info(TAG, `onDestroy`); 173 } 174 } 175 ``` 176