1e41f4b71Sopenharmony_ci# UIExtensionContext (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci**UIExtensionContext**, inherited from [ExtensionContext](js-apis-inner-application-extensionContext.md), provides the context environment for [UIExtensionAbility](js-apis-app-ability-uiExtensionAbility.md). It provides UIExtensionAbility-related configuration and APIs for operating the UIExtensionAbility. For example, you can use the APIs to start a UIExtensionAbility. 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> - The APIs of this module can be used only in the stage model. 9e41f4b71Sopenharmony_ci> - The APIs provided by this module are system APIs. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## UIExtensionContext.startAbilityForResultAsCaller 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_cistartAbilityForResultAsCaller(want: Want, options?: StartOptions): Promise<AbilityResult> 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciStarts an ability with the caller information specified. This API uses a promise to return the result. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciThe caller information is carried in **want** and identified at the system service layer. The ability can obtain the caller information from the **want** parameter in the **onCreate** lifecycle callback. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciWhen this API is used to start an ability, the caller information carried in **want** is not overwritten by the current application information. The system service layer can obtain the initial caller information. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci - Normally, you can call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller. 28e41f4b71Sopenharmony_ci - If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller. 29e41f4b71Sopenharmony_ci - If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to terminate the ability, the normal result is returned to the last caller, and an exception message, in which **resultCode** is **-1**, is returned to others. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci> **NOTE** 32e41f4b71Sopenharmony_ci> 33e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**System API**: This is a system API. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**Parameters** 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 44e41f4b71Sopenharmony_ci| ------- | --------------------------------------------------- | ---- | ------------------------- | 45e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes | Want information about the target ability. | 46e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | No | Parameters used for starting the ability.| 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci**Return value** 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci| Type | Description | 51e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------- | 52e41f4b71Sopenharmony_ci| Promise<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promise used to return the result.| 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**Error codes** 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci| ID| Error Message | 59e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------- | 60e41f4b71Sopenharmony_ci| 401| Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 61e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 62e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 63e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 64e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**Example** 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci```ts 69e41f4b71Sopenharmony_ciimport { UIExtensionAbility } from '@kit.AbilityKit'; 70e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciexport default class UIExtension extends UIExtensionAbility { 73e41f4b71Sopenharmony_ci onForeground() { 74e41f4b71Sopenharmony_ci this.context.startAbilityForResultAsCaller({ 75e41f4b71Sopenharmony_ci bundleName: 'com.example.startabilityforresultascaller', 76e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 77e41f4b71Sopenharmony_ci moduleName: 'entry' 78e41f4b71Sopenharmony_ci }).then((data) => { 79e41f4b71Sopenharmony_ci console.log('=======>startAbilityForResultAsCaller data Promise ======>' + JSON.stringify(data)); 80e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 81e41f4b71Sopenharmony_ci console.log('=======>startAbilityForResultAsCaller error.code Promise ======>' + error.code); 82e41f4b71Sopenharmony_ci }); 83e41f4b71Sopenharmony_ci } 84e41f4b71Sopenharmony_ci} 85e41f4b71Sopenharmony_ci``` 86