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