1# @ohos.application.StaticSubscriberExtensionContext (StaticSubscriberExtensionContext)
2
3The **StaticSubscriberExtensionContext** module, inherited from **ExtensionContext**, provides context for StaticSubscriberExtensionAbilities.
4
5You can use the APIs of this module to start StaticSubscriberExtensionAbilities.
6
7> **NOTE**
8>
9> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
10>
11> The APIs of this module can be used only in the stage model.
12>
13> The APIs provided by this module are system APIs.
14
15## Modules to Import
16
17```ts
18import { StaticSubscriberExtensionContext } from '@kit.BasicServicesKit';
19```
20
21## Usage
22
23Before using the **StaticSubscriberExtensionContext** module, you must first obtain a **StaticSubscriberExtensionAbility** instance.
24
25```ts
26import { StaticSubscriberExtensionAbility, StaticSubscriberExtensionContext } from '@kit.BasicServicesKit';
27```
28
29## StaticSubscriberExtensionContext.startAbility
30
31startAbility(want: Want, callback: AsyncCallback<void>): void;
32
33Starts an ability that belongs to the same application as this StaticSubscriberExtensionAbility. This API uses an asynchronous callback to return the result.
34
35Observe the following when using this API:
36 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
37 - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
38
39**Required permissions**: ohos.permission.START_ABILITIES_FROM_BACKGROUND
40
41**System capability**: SystemCapability.Ability.AbilityRuntime.Core
42
43**System API**: This is a system API.
44
45**Parameters**
46
47| Name  | Type                               | Mandatory| Description                      |
48| -------- | ----------------------------------- | ---- | -------------------------- |
49| want     | [Want](../apis-ability-kit/js-apis-wantAgent.md) | Yes  | Want information about the target ability.   |
50| callback | AsyncCallback<void>           | Yes  | Callback used to return the result.|
51
52**Error codes**
53
54| ID| Error Message                                                    |
55| -------- | ------------------------------------------------------------ |
56| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
57| 16000001 | The specified ability does not exist.                        |
58| 16000002 | Incorrect ability type.                                      |
59| 16000004 | Can not start invisible component.                           |
60| 16000005 | The specified process does not have the permission.          |
61| 16000006 | Cross-user operations are not allowed.                       |
62| 16000008 | The crowdtesting application expires.                        |
63| 16000009 | An ability cannot be started or stopped in Wukong mode.      |
64| 16000011 | The context does not exist.                                  |
65| 16000050 | Internal error.                                              |
66| 16000053 | The ability is not on the top of the UI.                     |
67| 16000055 | Installation-free timed out.                                 |
68| 16200001 | The caller has been released.                                |
69| 16300003 | The target application is not self application.              |
70
71For details about the error codes, see [Ability Error Codes](../apis-ability-kit/errorcode-ability.md).
72
73**Example**
74
75  ```ts
76import { commonEventManager, BusinessError } from '@kit.BasicServicesKit';
77import { Want } from '@kit.AbilityKit';
78
79let want: Want = {
80  bundleName: "com.example.myapp",
81  abilityName: "MyAbility"
82};
83
84class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility {
85  onReceiveEvent(event: commonEventManager.CommonEventData) {
86    console.log(`onReceiveEvent, event: ${JSON.stringify(event)}`);
87
88    try {
89      this.context.startAbility(want, (error: BusinessError) => {
90        if (error) {
91          // Process service logic errors.
92          console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
93            ' error.message: ' + JSON.stringify(error.message));
94          return;
95        }
96        // Carry out normal service processing.
97        console.log('startAbility succeed');
98      });
99    } catch (paramError) {
100      // Process input parameter errors.
101      let code = (paramError as BusinessError).code;
102      let message = (paramError as BusinessError).message;
103      console.log('startAbility failed, error.code: ' + JSON.stringify(code) +
104        ' error.message: ' + JSON.stringify(message));
105    }
106  }
107}
108  ```
109
110## StaticSubscriberExtensionContext.startAbility
111
112startAbility(want: Want): Promise<void>;
113
114Starts an ability that belongs to the same application as this StaticSubscriberExtensionAbility. This API uses a promise to return the result.
115
116Observe the following when using this API:
117 - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
118 - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
119
120**Required permissions**: ohos.permission.START_ABILITIES_FROM_BACKGROUND
121
122**System capability**: SystemCapability.Ability.AbilityRuntime.Core
123
124**System API**: This is a system API.
125
126**Parameters**
127
128| Name| Type                               | Mandatory| Description                   |
129| ------ | ----------------------------------- | ---- | ----------------------- |
130| want   | [Want](../apis-ability-kit/js-apis-wantAgent.md) | Yes  | Want information about the target ability.|
131
132**Return value**
133
134| Type               | Description                     |
135| ------------------- | ------------------------- |
136| Promise<void> | Promise used to return the result.|
137
138**Error codes**
139
140| ID| Error Message                                                    |
141| -------- | ------------------------------------------------------------ |
142| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
143| 16000001 | The specified ability does not exist.                        |
144| 16000002 | Incorrect ability type.                                      |
145| 16000004 | Can not start invisible component.                           |
146| 16000005 | The specified process does not have the permission.          |
147| 16000006 | Cross-user operations are not allowed.                       |
148| 16000008 | The crowdtesting application expires.                        |
149| 16000009 | An ability cannot be started or stopped in Wukong mode.      |
150| 16000011 | The context does not exist.                                  |
151| 16000050 | Internal error.                                              |
152| 16000053 | The ability is not on the top of the UI.                     |
153| 16000055 | Installation-free timed out.                                 |
154| 16200001 | The caller has been released.                                |
155| 16300003 | The target application is not self application.              |
156
157For details about the error codes, see [Ability Error Codes](../apis-ability-kit/errorcode-ability.md).
158
159**Example**
160
161  ```ts
162import { commonEventManager, BusinessError } from '@kit.BasicServicesKit';
163import { Want } from '@kit.AbilityKit';
164
165let want: Want = {
166  bundleName: "com.example.myapp",
167  abilityName: "MyAbility"
168};
169
170class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility {
171  onReceiveEvent(event: commonEventManager.CommonEventData) {
172    console.log(`onReceiveEvent, event: ${JSON.stringify(event)}`);
173    try {
174      this.context.startAbility(want)
175        .then(() => {
176          // Carry out normal service processing.
177          console.log('startAbility succeed');
178        })
179        .catch((error: BusinessError) => {
180          // Process service logic errors.
181          console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
182            ' error.message: ' + JSON.stringify(error.message));
183        });
184    } catch (paramError) {
185      // Process input parameter errors.
186      let code = (paramError as BusinessError).code;
187      let message = (paramError as BusinessError).message;
188      console.log('startAbility failed, error.code: ' + JSON.stringify(code) +
189        ' error.message: ' + JSON.stringify(message));
190    }
191  }
192}
193  ```
194