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