• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# UIAbilityContext (System API)
2
3**UIAbilityContext**, inherited from [Context](js-apis-inner-application-context.md), provides the context environment for [UIAbility](js-apis-app-ability-uiAbility.md) that needs to store its status. **UIAbilityContext** provides UIAbility-related configuration and APIs for operating UIAbilities and ServiceExtensionAbilities. For example, you can use the APIs to start a UIAbility, terminate a UIAbility to which the UIAbilityContext belongs, and start, terminate, connect to, or disconnect from a ServiceExtensionAbility.
4
5> **NOTE**
6>
7>  - The initial APIs of this module are supported since API version 9. 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> **NOTE**
18>
19> In the sample code provided in this topic, **this.context** is used to obtain **UIAbilityContext**, where **this** indicates a UIAbility instance inherited from **UIAbility**. To use **UIAbilityContext** APIs on pages, see [Obtaining the Context of UIAbility](../../application-models/uiability-usage.md#obtaining-the-context-of-uiability).
20
21## UIAbilityContext.startAbilityForResultWithAccount
22
23startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncCallback\<AbilityResult>): void
24
25Starts an ability with the account ID specified and returns the result when the ability is terminated. This API uses an asynchronous callback to return the result. It can be called only by the main thread.
26
27> **NOTE**
28>
29> 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).
30> Permission verification is not required when **accountId** specifies the current user.
31
32**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
33
34**System capability**: SystemCapability.Ability.AbilityRuntime.Core
35
36**System API**: This is a system API.
37
38**Parameters**
39
40| Name| Type| Mandatory| Description|
41| -------- | -------- | -------- | -------- |
42| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
43| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
44| callback | AsyncCallback&lt;[AbilityResult](js-apis-inner-ability-abilityResult.md)&gt; | Yes| Callback used to return the result.|
45
46**Error codes**
47
48For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
49
50| ID| Error Message|
51| ------- | -------------------------------- |
52| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
53| 16000001 | The specified ability does not exist. |
54| 16000002 | Incorrect ability type. |
55| 16000004 | Failed to start the invisible ability. |
56| 16000005 | The specified process does not have the permission. |
57| 16000006 | Cross-user operations are not allowed. |
58| 16000008 | The crowdtesting application expires. |
59| 16000009 | An ability cannot be started or stopped in Wukong mode. |
60| 16000010 | The call with the continuation flag is forbidden. |
61| 16000011 | The context does not exist. |
62| 16000012 | The application is controlled.        |
63| 16000013 | The application is controlled by EDM.       |
64| 16000019 | No matching ability is found. |
65| 16000050 | Internal error. |
66| 16000053 | The ability is not on the top of the UI. |
67| 16000055 | Installation-free timed out. |
68| 16000071 | App clone is not supported. |
69| 16000072 | App clone or multi-instance is not supported. |
70| 16000073 | The app clone index is invalid. |
71| 16000076 | The app instance key is invalid. |
72| 16000077 | The number of app instances reaches the limit. |
73| 16000078 | The multi-instance is not supported. |
74| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
75| 16000080 | Creating an instance is not supported. |
76| 16000082 | The UIAbility is being started. |
77| 16200001 | The caller has been released. |
78
79**Example**
80
81```ts
82import { UIAbility, common, Want } from '@kit.AbilityKit';
83import { BusinessError } from '@kit.BasicServicesKit';
84
85export default class EntryAbility extends UIAbility {
86  onForeground() {
87    let want: Want = {
88      deviceId: '',
89      bundleName: 'com.example.myapplication',
90      abilityName: 'EntryAbility'
91    };
92    let accountId = 100;
93
94    try {
95      this.context.startAbilityForResultWithAccount(want, accountId, (err: BusinessError, result: common.AbilityResult) => {
96        if (err.code) {
97          // Process service logic errors.
98          console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
99          return;
100        }
101        // Carry out normal service processing.
102        console.info('startAbilityForResultWithAccount succeed');
103      });
104    } catch (err) {
105      // Process input parameter errors.
106      let code = (err as BusinessError).code;
107      let message = (err as BusinessError).message;
108      console.error(`startAbilityForResultWithAccount failed, code is ${code}, message is ${message}`);
109    }
110  }
111}
112```
113
114
115## UIAbilityContext.startAbilityForResultWithAccount
116
117startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void
118
119Starts an ability with the account ID and start options specified and returns the result when the ability is terminated. This API uses an asynchronous callback to return the result. It can be called only by the main thread.
120
121> **NOTE**
122>
123> 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).
124> Permission verification is not required when **accountId** specifies the current user.
125
126**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
127
128**System capability**: SystemCapability.Ability.AbilityRuntime.Core
129
130**System API**: This is a system API.
131
132**Parameters**
133
134| Name| Type| Mandatory| Description|
135| -------- | -------- | -------- | -------- |
136| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
137| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
138| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.|
139| callback | AsyncCallback\<void\> | Yes| Callback invoked when the ability is terminated.|
140
141**Error codes**
142
143For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
144
145| ID| Error Message|
146| ------- | -------------------------------- |
147| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
148| 16000001 | The specified ability does not exist. |
149| 16000002 | Incorrect ability type. |
150| 16000004 | Failed to start the invisible ability. |
151| 16000005 | The specified process does not have the permission. |
152| 16000006 | Cross-user operations are not allowed. |
153| 16000008 | The crowdtesting application expires. |
154| 16000009 | An ability cannot be started or stopped in Wukong mode. |
155| 16000010 | The call with the continuation flag is forbidden. |
156| 16000011 | The context does not exist. |
157| 16000012 | The application is controlled.        |
158| 16000013 | The application is controlled by EDM.       |
159| 16000019 | No matching ability is found. |
160| 16000050 | Internal error. |
161| 16000053 | The ability is not on the top of the UI. |
162| 16000055 | Installation-free timed out. |
163| 16000071 | App clone is not supported. |
164| 16000072 | App clone or multi-instance is not supported. |
165| 16000073 | The app clone index is invalid. |
166| 16000076 | The app instance key is invalid. |
167| 16000077 | The number of app instances reaches the limit. |
168| 16000078 | The multi-instance is not supported. |
169| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
170| 16000080 | Creating an instance is not supported. |
171| 16000082 | The UIAbility is being started. |
172| 16200001 | The caller has been released. |
173
174**Example**
175
176```ts
177import { UIAbility, StartOptions, Want } from '@kit.AbilityKit';
178import { BusinessError } from '@kit.BasicServicesKit';
179
180export default class EntryAbility extends UIAbility {
181  onForeground() {
182    let want: Want = {
183      deviceId: '',
184      bundleName: 'com.example.myapplication',
185      abilityName: 'EntryAbility'
186    };
187    let accountId = 100;
188    let options: StartOptions = {
189      displayId: 0
190    };
191
192    try {
193      this.context.startAbilityForResultWithAccount(want, accountId, options, (err: BusinessError) => {
194        if (err.code) {
195          // Process service logic errors.
196          console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
197          return;
198        }
199        // Carry out normal service processing.
200        console.info('startAbilityForResultWithAccount succeed');
201      });
202    } catch (err) {
203      // Process input parameter errors.
204      let code = (err as BusinessError).code;
205      let message = (err as BusinessError).message;
206      console.error(`startAbilityForResultWithAccount failed, code is ${code}, message is ${message}`);
207    }
208  }
209}
210```
211
212
213## UIAbilityContext.startAbilityForResultWithAccount
214
215startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<AbilityResult\>
216
217Starts an ability with the account ID specified and returns the result when the ability is terminated. This API uses a promise to return the result. It can be called only by the main thread.
218
219> **NOTE**
220>
221> 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).
222> Permission verification is not required when **accountId** specifies the current user.
223
224**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
225
226**System capability**: SystemCapability.Ability.AbilityRuntime.Core
227
228**System API**: This is a system API.
229
230**Parameters**
231
232| Name| Type| Mandatory| Description|
233| -------- | -------- | -------- | -------- |
234| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
235| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
236| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.|
237
238**Return value**
239
240| Type| Description|
241| -------- | -------- |
242| Promise&lt;[AbilityResult](js-apis-inner-ability-abilityResult.md)&gt; | Promise used to return the ability result when the ability is terminated.|
243
244**Error codes**
245
246For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
247
248| ID| Error Message|
249| ------- | -------------------------------- |
250| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
251| 16000001 | The specified ability does not exist. |
252| 16000002 | Incorrect ability type. |
253| 16000004 | Failed to start the invisible ability. |
254| 16000005 | The specified process does not have the permission. |
255| 16000006 | Cross-user operations are not allowed. |
256| 16000008 | The crowdtesting application expires. |
257| 16000009 | An ability cannot be started or stopped in Wukong mode. |
258| 16000010 | The call with the continuation flag is forbidden. |
259| 16000011 | The context does not exist. |
260| 16000012 | The application is controlled.        |
261| 16000013 | The application is controlled by EDM.       |
262| 16000019 | No matching ability is found. |
263| 16000050 | Internal error. |
264| 16000053 | The ability is not on the top of the UI. |
265| 16000055 | Installation-free timed out. |
266| 16000071 | App clone is not supported. |
267| 16000072 | App clone or multi-instance is not supported. |
268| 16000073 | The app clone index is invalid. |
269| 16000076 | The app instance key is invalid. |
270| 16000077 | The number of app instances reaches the limit. |
271| 16000078 | The multi-instance is not supported. |
272| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
273| 16000080 | Creating an instance is not supported. |
274| 16000082 | The UIAbility is being started. |
275| 16200001 | The caller has been released. |
276
277**Example**
278
279```ts
280import { UIAbility, StartOptions, Want, common } from '@kit.AbilityKit';
281import { BusinessError } from '@kit.BasicServicesKit';
282
283export default class EntryAbility extends UIAbility {
284  onForeground() {
285    let want: Want = {
286      deviceId: '',
287      bundleName: 'com.example.myapplication',
288      abilityName: 'EntryAbility'
289    };
290    let accountId = 100;
291    let options: StartOptions = {
292      displayId: 0
293    };
294
295    try {
296      this.context.startAbilityForResultWithAccount(want, accountId, options)
297        .then((result: common.AbilityResult) => {
298          // Carry out normal service processing.
299          console.info('startAbilityForResultWithAccount succeed');
300        })
301        .catch((err: BusinessError) => {
302          // Process service logic errors.
303          console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
304        });
305    } catch (err) {
306      // Process input parameter errors.
307      let code = (err as BusinessError).code;
308      let message = (err as BusinessError).message;
309      console.error(`startAbilityForResultWithAccount failed, code is ${code}, message is ${message}`);
310    }
311  }
312}
313```
314## UIAbilityContext.startServiceExtensionAbility
315
316startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void
317
318Starts a ServiceExtensionAbility. This API uses an asynchronous callback to return the result.
319
320**System capability**: SystemCapability.Ability.AbilityRuntime.Core
321
322**System API**: This is a system API.
323
324**Parameters**
325
326| Name| Type| Mandatory| Description|
327| -------- | -------- | -------- | -------- |
328| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
329| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
330
331**Error codes**
332
333For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
334
335| ID| Error Message|
336| ------- | -------------------------------- |
337| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
338| 16000001 | The specified ability does not exist. |
339| 16000002 | Incorrect ability type. |
340| 16000004 | Failed to start the invisible ability. |
341| 16000005 | The specified process does not have the permission. |
342| 16000006 | Cross-user operations are not allowed. |
343| 16000008 | The crowdtesting application expires. |
344| 16000011 | The context does not exist. |
345| 16000012 | The application is controlled.        |
346| 16000013 | The application is controlled by EDM.       |
347| 16000019 | No matching ability is found. |
348| 16000050 | Internal error. |
349| 16200001 | The caller has been released. |
350
351**Example**
352
353```ts
354import { UIAbility, Want } from '@kit.AbilityKit';
355import { BusinessError } from '@kit.BasicServicesKit';
356
357export default class EntryAbility extends UIAbility {
358  onForeground() {
359    let want: Want = {
360      deviceId: '',
361      bundleName: 'com.example.myapplication',
362      abilityName: 'ServiceExtensionAbility'
363    };
364
365    try {
366      this.context.startServiceExtensionAbility(want, (error: BusinessError) => {
367        if (error.code) {
368          // Process service logic errors.
369          console.error(`startServiceExtensionAbility failed, code is ${error.code}, message is ${error.message}`);
370          return;
371        }
372        // Carry out normal service processing.
373        console.info('startServiceExtensionAbility succeed');
374      });
375    } catch (err) {
376      // Process input parameter errors.
377      let code = (err as BusinessError).code;
378      let message = (err as BusinessError).message;
379      console.error(`startServiceExtensionAbility failed, code is ${code}, message is ${message}`);
380    }
381  }
382}
383```
384
385## UIAbilityContext.startServiceExtensionAbility
386
387startServiceExtensionAbility(want: Want): Promise\<void>
388
389Starts a ServiceExtensionAbility. This API uses a promise to return the result.
390
391**System capability**: SystemCapability.Ability.AbilityRuntime.Core
392
393**System API**: This is a system API.
394
395**Parameters**
396
397| Name| Type| Mandatory| Description|
398| -------- | -------- | -------- | -------- |
399| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
400
401**Error codes**
402
403For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
404
405| ID| Error Message|
406| ------- | -------------------------------- |
407| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
408| 16000001 | The specified ability does not exist. |
409| 16000002 | Incorrect ability type. |
410| 16000004 | Failed to start the invisible ability. |
411| 16000005 | The specified process does not have the permission. |
412| 16000006 | Cross-user operations are not allowed. |
413| 16000008 | The crowdtesting application expires. |
414| 16000011 | The context does not exist. |
415| 16000012 | The application is controlled.        |
416| 16000013 | The application is controlled by EDM.       |
417| 16000019 | No matching ability is found. |
418| 16000050 | Internal error. |
419| 16200001 | The caller has been released. |
420
421**Example**
422
423```ts
424import { UIAbility, Want } from '@kit.AbilityKit';
425import { BusinessError } from '@kit.BasicServicesKit';
426
427export default class EntryAbility extends UIAbility {
428  onForeground() {
429    let want: Want = {
430      deviceId: '',
431      bundleName: 'com.example.myapplication',
432      abilityName: 'ServiceExtensionAbility'
433    };
434
435    try {
436      this.context.startServiceExtensionAbility(want)
437        .then(() => {
438          // Carry out normal service processing.
439          console.info('startServiceExtensionAbility succeed');
440        })
441        .catch((err: BusinessError) => {
442          // Process service logic errors.
443          console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
444        });
445    } catch (err) {
446      // Process input parameter errors.
447      let code = (err as BusinessError).code;
448      let message = (err as BusinessError).message;
449      console.error(`startServiceExtensionAbility failed, code is ${code}, message is ${message}`);
450    }
451  }
452}
453```
454
455## UIAbilityContext.startServiceExtensionAbilityWithAccount
456
457startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void
458
459Starts a ServiceExtensionAbility with the account ID specified. This API uses an asynchronous callback to return the result.
460
461> **NOTE**
462>
463> 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).
464> Permission verification is not required when **accountId** specifies the current user.
465
466**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
467
468**System capability**: SystemCapability.Ability.AbilityRuntime.Core
469
470**System API**: This is a system API.
471
472**Parameters**
473
474| Name| Type| Mandatory| Description|
475| -------- | -------- | -------- | -------- |
476| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
477| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
478| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
479
480**Error codes**
481
482For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
483
484| ID| Error Message|
485| ------- | -------------------------------- |
486| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
487| 16000001 | The specified ability does not exist. |
488| 16000002 | Incorrect ability type. |
489| 16000004 | Failed to start the invisible ability. |
490| 16000005 | The specified process does not have the permission. |
491| 16000006 | Cross-user operations are not allowed. |
492| 16000008 | The crowdtesting application expires. |
493| 16000011 | The context does not exist. |
494| 16000012 | The application is controlled.        |
495| 16000013 | The application is controlled by EDM.       |
496| 16000019 | No matching ability is found. |
497| 16000050 | Internal error. |
498| 16200001 | The caller has been released. |
499
500**Example**
501
502```ts
503import { UIAbility, Want } from '@kit.AbilityKit';
504import { BusinessError } from '@kit.BasicServicesKit';
505
506export default class EntryAbility extends UIAbility {
507  onForeground() {
508    let want: Want = {
509      deviceId: '',
510      bundleName: 'com.example.myapplication',
511      abilityName: 'ServiceExtensionAbility'
512    };
513    let accountId = 100;
514
515    try {
516      this.context.startServiceExtensionAbilityWithAccount(want, accountId, (err: BusinessError) => {
517        if (err.code) {
518          // Process service logic errors.
519          console.error(`startServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
520          return;
521        }
522        // Carry out normal service processing.
523        console.info('startServiceExtensionAbilityWithAccount succeed');
524      });
525    } catch (err) {
526      // Process input parameter errors.
527      let code = (err as BusinessError).code;
528      let message = (err as BusinessError).message;
529      console.error(`startServiceExtensionAbilityWithAccount failed, code is ${code}, message is ${message}`);
530    }
531  }
532}
533```
534
535## UIAbilityContext.startServiceExtensionAbilityWithAccount
536
537startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>
538
539Starts a ServiceExtensionAbility with the account ID specified. This API uses a promise to return the result.
540
541> **NOTE**
542>
543> 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).
544> Permission verification is not required when **accountId** specifies the current user.
545
546**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
547
548**System capability**: SystemCapability.Ability.AbilityRuntime.Core
549
550**System API**: This is a system API.
551
552**Parameters**
553
554| Name| Type| Mandatory| Description|
555| -------- | -------- | -------- | -------- |
556| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
557| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
558
559**Error codes**
560
561For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
562
563| ID| Error Message|
564| ------- | -------------------------------- |
565| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
566| 16000001 | The specified ability does not exist. |
567| 16000002 | Incorrect ability type. |
568| 16000004 | Failed to start the invisible ability. |
569| 16000005 | The specified process does not have the permission. |
570| 16000006 | Cross-user operations are not allowed. |
571| 16000008 | The crowdtesting application expires. |
572| 16000011 | The context does not exist. |
573| 16000012 | The application is controlled.        |
574| 16000013 | The application is controlled by EDM.       |
575| 16000019 | No matching ability is found. |
576| 16000050 | Internal error. |
577| 16200001 | The caller has been released. |
578
579**Example**
580
581```ts
582import { UIAbility, Want } from '@kit.AbilityKit';
583import { BusinessError } from '@kit.BasicServicesKit';
584
585export default class EntryAbility extends UIAbility {
586  onForeground() {
587    let want: Want = {
588      deviceId: '',
589      bundleName: 'com.example.myapplication',
590      abilityName: 'ServiceExtensionAbility'
591    };
592    let accountId = 100;
593
594    try {
595      this.context.startServiceExtensionAbilityWithAccount(want, accountId)
596        .then(() => {
597          // Carry out normal service processing.
598          console.info('startServiceExtensionAbilityWithAccount succeed');
599        })
600        .catch((err: BusinessError) => {
601          // Process service logic errors.
602          console.error(`startServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
603        });
604    } catch (err) {
605      // Process input parameter errors.
606      let code = (err as BusinessError).code;
607      let message = (err as BusinessError).message;
608      console.error(`startServiceExtensionAbilityWithAccount failed, code is ${code}, message is ${message}`);
609    }
610  }
611}
612```
613## UIAbilityContext.stopServiceExtensionAbility
614
615stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void
616
617Stops a ServiceExtensionAbility in the same application. This API uses an asynchronous callback to return the result.
618
619**System capability**: SystemCapability.Ability.AbilityRuntime.Core
620
621**System API**: This is a system API.
622
623**Parameters**
624
625| Name| Type| Mandatory| Description|
626| -------- | -------- | -------- | -------- |
627| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
628| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
629
630**Error codes**
631
632For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
633
634| ID| Error Message|
635| ------- | -------------------------------- |
636| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
637| 16000001 | The specified ability does not exist. |
638| 16000002 | Incorrect ability type. |
639| 16000004 | Failed to start the invisible ability. |
640| 16000005 | The specified process does not have the permission. |
641| 16000006 | Cross-user operations are not allowed. |
642| 16000011 | The context does not exist. |
643| 16000012 | The application is controlled.        |
644| 16000013 | The application is controlled by EDM.       |
645| 16000050 | Internal error. |
646| 16200001 | The caller has been released. |
647
648**Example**
649
650```ts
651import { UIAbility, Want } from '@kit.AbilityKit';
652import { BusinessError } from '@kit.BasicServicesKit';
653
654export default class EntryAbility extends UIAbility {
655  onForeground() {
656    let want: Want = {
657      deviceId: '',
658      bundleName: 'com.example.myapplication',
659      abilityName: 'ServiceExtensionAbility'
660    };
661
662    try {
663      this.context.stopServiceExtensionAbility(want, (err: BusinessError) => {
664        if (err.code) {
665          // Process service logic errors.
666          console.error(`stopServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
667          return;
668        }
669        // Carry out normal service processing.
670        console.info('stopServiceExtensionAbility succeed');
671      });
672    } catch (err) {
673      // Process input parameter errors.
674      let code = (err as BusinessError).code;
675      let message = (err as BusinessError).message;
676      console.error(`stopServiceExtensionAbility failed, code is ${code}, message is ${message}`);
677    }
678  }
679}
680```
681
682## UIAbilityContext.stopServiceExtensionAbility
683
684stopServiceExtensionAbility(want: Want): Promise\<void>
685
686Stops a ServiceExtensionAbility in the same application. This API uses a promise to return the result.
687
688**System capability**: SystemCapability.Ability.AbilityRuntime.Core
689
690**System API**: This is a system API.
691
692**Parameters**
693
694| Name| Type| Mandatory| Description|
695| -------- | -------- | -------- | -------- |
696| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
697
698**Error codes**
699
700For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
701
702| ID| Error Message|
703| ------- | -------------------------------- |
704| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
705| 16000001 | The specified ability does not exist. |
706| 16000002 | Incorrect ability type. |
707| 16000004 | Failed to start the invisible ability. |
708| 16000005 | The specified process does not have the permission. |
709| 16000006 | Cross-user operations are not allowed. |
710| 16000011 | The context does not exist. |
711| 16000050 | Internal error. |
712| 16200001 | The caller has been released. |
713
714**Example**
715
716```ts
717import { UIAbility, Want } from '@kit.AbilityKit';
718import { BusinessError } from '@kit.BasicServicesKit';
719
720export default class EntryAbility extends UIAbility {
721  onForeground() {
722    let want: Want = {
723      deviceId: '',
724      bundleName: 'com.example.myapplication',
725      abilityName: 'ServiceExtensionAbility'
726    };
727
728    try {
729      this.context.stopServiceExtensionAbility(want)
730        .then(() => {
731          // Carry out normal service processing.
732          console.info('stopServiceExtensionAbility succeed');
733        })
734        .catch((err: BusinessError) => {
735          // Process service logic errors.
736          console.error(`stopServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
737        });
738    } catch (err) {
739      // Process input parameter errors.
740      let code = (err as BusinessError).code;
741      let message = (err as BusinessError).message;
742      console.error(`stopServiceExtensionAbility failed, code is ${code}, message is ${message}`);
743    }
744  }
745}
746```
747
748## UIAbilityContext.stopServiceExtensionAbilityWithAccount
749
750stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void
751
752Stops a ServiceExtensionAbility with the account ID specified in the same application. This API uses an asynchronous callback to return the result.
753
754> **NOTE**
755>
756> Permission verification is not required when **accountId** specifies the current user.
757
758**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
759
760**System capability**: SystemCapability.Ability.AbilityRuntime.Core
761
762**System API**: This is a system API.
763
764**Parameters**
765
766| Name| Type| Mandatory| Description|
767| -------- | -------- | -------- | -------- |
768| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
769| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
770| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
771
772**Error codes**
773
774For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
775
776| ID| Error Message|
777| ------- | -------------------------------- |
778| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
779| 16000001 | The specified ability does not exist. |
780| 16000002 | Incorrect ability type. |
781| 16000004 | Failed to start the invisible ability. |
782| 16000005 | The specified process does not have the permission. |
783| 16000006 | Cross-user operations are not allowed. |
784| 16000011 | The context does not exist. |
785| 16000050 | Internal error. |
786| 16200001 | The caller has been released. |
787
788**Example**
789
790```ts
791import { UIAbility, Want } from '@kit.AbilityKit';
792import { BusinessError } from '@kit.BasicServicesKit';
793
794export default class EntryAbility extends UIAbility {
795  onForeground() {
796    let want: Want = {
797      deviceId: '',
798      bundleName: 'com.example.myapplication',
799      abilityName: 'ServiceExtensionAbility'
800    };
801    let accountId = 100;
802
803    try {
804      this.context.stopServiceExtensionAbilityWithAccount(want, accountId, (err: BusinessError) => {
805        if (err.code) {
806          // Process service logic errors.
807          console.error(`stopServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
808          return;
809        }
810        // Carry out normal service processing.
811        console.info('stopServiceExtensionAbilityWithAccount succeed');
812      });
813    } catch (err) {
814      // Process input parameter errors.
815      let code = (err as BusinessError).code;
816      let message = (err as BusinessError).message;
817      console.error(`stopServiceExtensionAbilityWithAccount failed, code is ${code}, message is ${message}`);
818    }
819  }
820}
821```
822
823## UIAbilityContext.stopServiceExtensionAbilityWithAccount
824
825stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>
826
827Stops a ServiceExtensionAbility with the account ID specified in the same application. This API uses a promise to return the result.
828
829> **NOTE**
830>
831> Permission verification is not required when **accountId** specifies the current user.
832
833**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
834
835**System capability**: SystemCapability.Ability.AbilityRuntime.Core
836
837**System API**: This is a system API.
838
839**Parameters**
840
841| Name| Type| Mandatory| Description|
842| -------- | -------- | -------- | -------- |
843| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
844| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
845
846**Error codes**
847
848For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
849
850| ID| Error Message|
851| ------- | -------------------------------- |
852| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
853| 16000001 | The specified ability does not exist. |
854| 16000002 | Incorrect ability type. |
855| 16000004 | Failed to start the invisible ability. |
856| 16000005 | The specified process does not have the permission. |
857| 16000006 | Cross-user operations are not allowed. |
858| 16000011 | The context does not exist. |
859| 16000050 | Internal error. |
860| 16200001 | The caller has been released. |
861
862**Example**
863
864```ts
865import { UIAbility, Want } from '@kit.AbilityKit';
866import { BusinessError } from '@kit.BasicServicesKit';
867
868export default class EntryAbility extends UIAbility {
869  onForeground() {
870    let want: Want = {
871      deviceId: '',
872      bundleName: 'com.example.myapplication',
873      abilityName: 'ServiceExtensionAbility'
874    };
875    let accountId = 100;
876
877    try {
878      this.context.stopServiceExtensionAbilityWithAccount(want, accountId)
879        .then(() => {
880          // Carry out normal service processing.
881          console.info('stopServiceExtensionAbilityWithAccount succeed');
882        })
883        .catch((err: BusinessError) => {
884          // Process service logic errors.
885          console.error(`stopServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
886        });
887    } catch (err) {
888      // Process input parameter errors.
889      let code = (err as BusinessError).code;
890      let message = (err as BusinessError).message;
891      console.error(`stopServiceExtensionAbilityWithAccount failed, code is ${code}, message is ${message}`);
892    }
893  }
894}
895```
896
897## UIAbilityContext.connectServiceExtensionAbilityWithAccount
898
899connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number
900
901Connects this ability to a ServiceExtensionAbility, with the account ID specified. This API can be called only by the main thread.
902
903Currently, this API takes effect only on mobile phones and tablets.
904
905> **NOTE**
906>
907> 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).
908> Permission verification is not required when **accountId** specifies the current user.
909
910**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
911
912**System capability**: SystemCapability.Ability.AbilityRuntime.Core
913
914**System API**: This is a system API.
915
916**Parameters**
917
918| Name| Type| Mandatory| Description|
919| -------- | -------- | -------- | -------- |
920| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
921| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
922| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes| Instance of the callback function after the connection to the ServiceExtensionAbility is set up.|
923
924**Return value**
925
926| Type| Description|
927| -------- | -------- |
928| number | Result code of the ability connection.|
929
930**Error codes**
931
932For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
933
934| ID| Error Message|
935| ------- | -------------------------------- |
936| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
937| 16000001 | The specified ability does not exist. |
938| 16000002 | Incorrect ability type. |
939| 16000004 | Failed to start the invisible ability. |
940| 16000005 | The specified process does not have the permission. |
941| 16000006 | Cross-user operations are not allowed. |
942| 16000008 | The crowdtesting application expires. |
943| 16000053 | The ability is not on the top of the UI. |
944| 16000055 | Installation-free timed out. |
945| 16000011 | The context does not exist.        |
946| 16000050 | Internal error. |
947
948**Example**
949
950```ts
951import { UIAbility, Want, common } from '@kit.AbilityKit';
952import { rpc } from '@kit.IPCKit';
953import { BusinessError } from '@kit.BasicServicesKit';
954
955export default class EntryAbility extends UIAbility {
956  onForeground() {
957    let want: Want = {
958      deviceId: '',
959      bundleName: 'com.example.myapplication',
960      abilityName: 'ServiceExtensionAbility'
961    };
962    let accountId = 100;
963    let commRemote: rpc.IRemoteObject;
964    let options: common.ConnectOptions = {
965      onConnect(elementName, remote) {
966        commRemote = remote;
967        console.info('onConnect...');
968      },
969      onDisconnect(elementName) {
970        console.info('onDisconnect...');
971      },
972      onFailed(code) {
973        console.info('onFailed...');
974      }
975    };
976    let connection: number;
977
978    try {
979      connection = this.context.connectServiceExtensionAbilityWithAccount(want, accountId, options);
980    } catch (err) {
981      // Process input parameter errors.
982      let code = (err as BusinessError).code;
983      let message = (err as BusinessError).message;
984      console.error(`connectServiceExtensionAbility failed, code is ${code}, message is ${message}`);
985    }
986  }
987}
988```
989
990## UIAbilityContext.startAbilityWithAccount
991
992startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void\>): void
993
994Starts an ability with want and the account ID specified. This API uses an asynchronous callback to return the result. It can be called only by the main thread.
995
996> **NOTE**
997>
998> 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).
999> Permission verification is not required when **accountId** specifies the current user.
1000
1001**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1002
1003**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1004
1005**System API**: This is a system API.
1006
1007**Parameters**
1008
1009| Name| Type| Mandatory| Description|
1010| -------- | -------- | -------- | -------- |
1011| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
1012| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
1013| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
1014
1015**Error codes**
1016
1017For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1018
1019| ID| Error Message|
1020| ------- | -------------------------------- |
1021| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1022| 16000001 | The specified ability does not exist. |
1023| 16000002 | Incorrect ability type. |
1024| 16000004 | Failed to start the invisible ability. |
1025| 16000005 | The specified process does not have the permission. |
1026| 16000006 | Cross-user operations are not allowed. |
1027| 16000008 | The crowdtesting application expires. |
1028| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1029| 16000010 | The call with the continuation flag is forbidden. |
1030| 16000011 | The context does not exist. |
1031| 16000012 | The application is controlled.        |
1032| 16000013 | The application is controlled by EDM.       |
1033| 16000019 | No matching ability is found. |
1034| 16000050 | Internal error. |
1035| 16000053 | The ability is not on the top of the UI. |
1036| 16000055 | Installation-free timed out. |
1037| 16000071 | App clone is not supported. |
1038| 16000072 | App clone or multi-instance is not supported. |
1039| 16000073 | The app clone index is invalid. |
1040| 16000076 | The app instance key is invalid. |
1041| 16000077 | The number of app instances reaches the limit. |
1042| 16000078 | The multi-instance is not supported. |
1043| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
1044| 16000080 | Creating an instance is not supported. |
1045| 16000082 | The UIAbility is being started. |
1046| 16200001 | The caller has been released. |
1047
1048**Example**
1049
1050```ts
1051import { UIAbility, Want } from '@kit.AbilityKit';
1052import { BusinessError } from '@kit.BasicServicesKit';
1053
1054export default class EntryAbility extends UIAbility {
1055  onForeground() {
1056    let want: Want = {
1057      deviceId: '',
1058      bundleName: 'com.example.myapplication',
1059      abilityName: 'EntryAbility'
1060    };
1061    let accountId = 100;
1062
1063    try {
1064      this.context.startAbilityWithAccount(want, accountId, (err: BusinessError) => {
1065        if (err.code) {
1066          // Process service logic errors.
1067          console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
1068          return;
1069        }
1070        // Carry out normal service processing.
1071        console.info('startAbilityWithAccount succeed');
1072      });
1073    } catch (err) {
1074      // Process input parameter errors.
1075      let code = (err as BusinessError).code;
1076      let message = (err as BusinessError).message;
1077      console.error(`startAbilityWithAccount failed, code is ${code}, message is ${message}`);
1078    }
1079  }
1080}
1081```
1082
1083
1084## UIAbilityContext.startAbilityWithAccount
1085
1086startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void
1087
1088Starts an ability with want, the account ID, and start options specified. This API uses an asynchronous callback to return the result. It can be called only by the main thread.
1089
1090> **NOTE**
1091>
1092> 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).
1093> Permission verification is not required when **accountId** specifies the current user.
1094
1095**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1096
1097**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1098
1099**System API**: This is a system API.
1100
1101**Parameters**
1102
1103| Name| Type| Mandatory| Description|
1104| -------- | -------- | -------- | -------- |
1105| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
1106| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
1107| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.|
1108| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
1109
1110**Error codes**
1111
1112For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1113
1114| ID| Error Message|
1115| ------- | -------------------------------- |
1116| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1117| 16000001 | The specified ability does not exist. |
1118| 16000002 | Incorrect ability type. |
1119| 16000004 | Failed to start the invisible ability. |
1120| 16000005 | The specified process does not have the permission. |
1121| 16000006 | Cross-user operations are not allowed. |
1122| 16000008 | The crowdtesting application expires. |
1123| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1124| 16000010 | The call with the continuation flag is forbidden. |
1125| 16000011 | The context does not exist. |
1126| 16000012 | The application is controlled.        |
1127| 16000013 | The application is controlled by EDM.       |
1128| 16000019 | No matching ability is found. |
1129| 16000050 | Internal error. |
1130| 16000053 | The ability is not on the top of the UI. |
1131| 16000055 | Installation-free timed out. |
1132| 16000071 | App clone is not supported. |
1133| 16000072 | App clone or multi-instance is not supported. |
1134| 16000073 | The app clone index is invalid. |
1135| 16000076 | The app instance key is invalid. |
1136| 16000077 | The number of app instances reaches the limit. |
1137| 16000078 | The multi-instance is not supported. |
1138| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
1139| 16000080 | Creating an instance is not supported. |
1140| 16000082 | The UIAbility is being started. |
1141| 16200001 | The caller has been released. |
1142
1143**Example**
1144
1145```ts
1146import { UIAbility, Want, StartOptions } from '@kit.AbilityKit';
1147import { BusinessError } from '@kit.BasicServicesKit';
1148
1149export default class EntryAbility extends UIAbility {
1150  onForeground() {
1151    let want: Want = {
1152      deviceId: '',
1153      bundleName: 'com.example.myapplication',
1154      abilityName: 'EntryAbility'
1155    };
1156    let accountId = 100;
1157    let options: StartOptions = {
1158      displayId: 0
1159    };
1160
1161    try {
1162      this.context.startAbilityWithAccount(want, accountId, options, (err: BusinessError) => {
1163        if (err.code) {
1164          // Process service logic errors.
1165          console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
1166          return;
1167        }
1168        // Carry out normal service processing.
1169        console.info('startAbilityWithAccount succeed');
1170      });
1171    } catch (err) {
1172      // Process input parameter errors.
1173      let code = (err as BusinessError).code;
1174      let message = (err as BusinessError).message;
1175      console.error(`startAbilityWithAccount failed, code is ${code}, message is ${message}`);
1176    }
1177  }
1178}
1179```
1180
1181
1182## UIAbilityContext.startAbilityWithAccount
1183
1184startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<void\>
1185
1186Starts an ability with want, the account ID, and start options specified. This API uses a promise to return the result. It can be called only by the main thread.
1187
1188> **NOTE**
1189>
1190> 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).
1191> Permission verification is not required when **accountId** specifies the current user.
1192
1193**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1194
1195**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1196
1197**System API**: This is a system API.
1198
1199**Parameters**
1200
1201| Name| Type| Mandatory| Description|
1202| -------- | -------- | -------- | -------- |
1203| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
1204| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
1205| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.|
1206
1207**Error codes**
1208
1209For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1210
1211| ID| Error Message|
1212| ------- | -------------------------------- |
1213| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1214| 16000001 | The specified ability does not exist. |
1215| 16000002 | Incorrect ability type. |
1216| 16000004 | Failed to start the invisible ability. |
1217| 16000005 | The specified process does not have the permission. |
1218| 16000006 | Cross-user operations are not allowed. |
1219| 16000008 | The crowdtesting application expires. |
1220| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1221| 16000010 | The call with the continuation flag is forbidden. |
1222| 16000011 | The context does not exist. |
1223| 16000012 | The application is controlled.        |
1224| 16000013 | The application is controlled by EDM.       |
1225| 16000019 | No matching ability is found. |
1226| 16000050 | Internal error. |
1227| 16000053 | The ability is not on the top of the UI. |
1228| 16000055 | Installation-free timed out. |
1229| 16000071 | App clone is not supported. |
1230| 16000072 | App clone or multi-instance is not supported. |
1231| 16000073 | The app clone index is invalid. |
1232| 16000076 | The app instance key is invalid. |
1233| 16000077 | The number of app instances reaches the limit. |
1234| 16000078 | The multi-instance is not supported. |
1235| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
1236| 16000080 | Creating an instance is not supported. |
1237| 16000082 | The UIAbility is being started. |
1238| 16200001 | The caller has been released. |
1239
1240**Example**
1241
1242```ts
1243import { UIAbility, Want, StartOptions } from '@kit.AbilityKit';
1244import { BusinessError } from '@kit.BasicServicesKit';
1245
1246export default class EntryAbility extends UIAbility {
1247  onForeground() {
1248    let want: Want = {
1249      deviceId: '',
1250      bundleName: 'com.example.myapplication',
1251      abilityName: 'EntryAbility'
1252    };
1253    let accountId = 100;
1254    let options: StartOptions = {
1255      displayId: 0
1256    };
1257
1258    try {
1259      this.context.startAbilityWithAccount(want, accountId, options)
1260        .then(() => {
1261          // Carry out normal service processing.
1262          console.info('startAbilityWithAccount succeed');
1263        })
1264        .catch((err: BusinessError) => {
1265          // Process service logic errors.
1266          console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
1267        });
1268    } catch (err) {
1269      // Process input parameter errors.
1270      let code = (err as BusinessError).code;
1271      let message = (err as BusinessError).message;
1272      console.error(`startAbilityWithAccount failed, code is ${code}, message is ${message}`);
1273    }
1274  }
1275}
1276```
1277
1278## UIAbilityContext.setMissionIcon
1279
1280setMissionIcon(icon: image.PixelMap, callback: AsyncCallback\<void>): void
1281
1282Sets an icon for this ability in the mission. This API uses an asynchronous callback to return the result. The maximum size of the icon is 600 MB.
1283
1284**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1285
1286**System API**: This is a system API.
1287
1288**Parameters**
1289
1290| Name| Type| Mandatory| Description|
1291| -------- | -------- | -------- | -------- |
1292| icon | image.PixelMap | Yes| Icon of the ability to set.|
1293| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
1294
1295**Error codes**
1296
1297For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1298
1299| ID| Error Message|
1300| ------- | -------------------------------- |
1301| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1302| 16000011 | The context does not exist. |
1303| 16000050 | Internal error. |
1304
1305**Example**
1306
1307```ts
1308import { UIAbility } from '@kit.AbilityKit';
1309import { image } from '@kit.ImageKit';
1310import { BusinessError } from '@kit.BasicServicesKit';
1311
1312export default class EntryAbility extends UIAbility {
1313  onForeground() {
1314    let imagePixelMap: image.PixelMap;
1315    let color = new ArrayBuffer(0);
1316    image.createPixelMap(color, {
1317      size: {
1318        height: 100,
1319        width: 100
1320      }
1321    }).then((data) => {
1322      imagePixelMap = data;
1323      this.context.setMissionIcon(imagePixelMap, (err: BusinessError) => {
1324        console.error(`setMissionLabel failed, code is ${err.code}, message is ${err.message}`);
1325      })
1326    }).catch((err: BusinessError) => {
1327      console.error(`createPixelMap failed, code is ${err.code}, message is ${err.message}`);
1328    });
1329  }
1330}
1331```
1332
1333
1334## UIAbilityContext.setMissionIcon
1335
1336setMissionIcon(icon: image.PixelMap): Promise\<void>
1337
1338Sets an icon for this ability in the mission. This API uses a promise to return the result. The maximum size of the icon is 600 MB.
1339
1340**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1341
1342**System API**: This is a system API.
1343
1344**Parameters**
1345
1346| Name| Type| Mandatory| Description|
1347| -------- | -------- | -------- | -------- |
1348| icon | image.PixelMap | Yes| Icon of the ability to set.|
1349
1350**Return value**
1351
1352| Type| Description|
1353| -------- | -------- |
1354| Promise&lt;void&gt; | Promise used to return the result.|
1355
1356**Error codes**
1357
1358For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1359
1360| ID| Error Message|
1361| ------- | -------------------------------- |
1362| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1363| 16000011 | The context does not exist. |
1364| 16000050 | Internal error. |
1365
1366**Example**
1367
1368```ts
1369import { UIAbility } from '@kit.AbilityKit';
1370import { image } from '@kit.ImageKit';
1371import { BusinessError } from '@kit.BasicServicesKit';
1372
1373export default class EntryAbility extends UIAbility {
1374  onForeground() {
1375    let imagePixelMap: image.PixelMap;
1376    let color = new ArrayBuffer(0);
1377    image.createPixelMap(color, {
1378      size: {
1379        height: 100,
1380        width: 100
1381      }
1382    }).then((data) => {
1383      imagePixelMap = data;
1384      this.context.setMissionIcon(imagePixelMap)
1385        .then(() => {
1386          console.info('setMissionIcon succeed');
1387        })
1388        .catch((err: BusinessError) => {
1389          console.error(`setMissionLabel failed, code is ${err.code}, message is ${err.message}`);
1390        });
1391    }).catch((err: BusinessError) => {
1392      console.error(`createPixelMap failed, code is ${err.code}, message is ${err.message}`);
1393    });
1394  }
1395}
1396```
1397
1398## UIAbilityContext.startRecentAbility
1399
1400startRecentAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
1401
1402Starts an ability. If the ability has multiple instances, the latest instance is started. This API uses an asynchronous callback to return the result. It can be called only by the main thread.
1403
1404> **NOTE**
1405>
1406> 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).
1407
1408**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1409
1410**System API**: This is a system API.
1411
1412**Parameters**
1413
1414| Name| Type| Mandatory| Description|
1415| -------- | -------- | -------- | -------- |
1416| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
1417| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
1418
1419**Error codes**
1420
1421For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1422
1423| ID| Error Message|
1424| ------- | -------------------------------- |
1425| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1426| 16000001 | The specified ability does not exist. |
1427| 16000002 | Incorrect ability type. |
1428| 16000004 | Failed to start the invisible ability. |
1429| 16000005 | The specified process does not have the permission. |
1430| 16000006 | Cross-user operations are not allowed. |
1431| 16000008 | The crowdtesting application expires. |
1432| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1433| 16000010 | The call with the continuation flag is forbidden. |
1434| 16000011 | The context does not exist. |
1435| 16000012 | The application is controlled.        |
1436| 16000013 | The application is controlled by EDM.       |
1437| 16000050 | Internal error. |
1438| 16000053 | The ability is not on the top of the UI. |
1439| 16000055 | Installation-free timed out. |
1440| 16000082 | The UIAbility is being started. |
1441| 16200001 | The caller has been released. |
1442| 16000073 | The app clone index is invalid. |
1443
1444**Example**
1445
1446```ts
1447import { UIAbility, Want } from '@kit.AbilityKit';
1448import { BusinessError } from '@kit.BasicServicesKit';
1449
1450export default class EntryAbility extends UIAbility {
1451  onForeground() {
1452    let want: Want = {
1453      bundleName: 'com.example.myapplication',
1454      abilityName: 'EntryAbility'
1455    };
1456
1457    try {
1458      this.context.startRecentAbility(want, (err: BusinessError) => {
1459        if (err.code) {
1460          // Process service logic errors.
1461          console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`);
1462          return;
1463        }
1464        // Carry out normal service processing.
1465        console.info('startRecentAbility succeed');
1466      });
1467    } catch (err) {
1468      // Process input parameter errors.
1469      let code = (err as BusinessError).code;
1470      let message = (err as BusinessError).message;
1471      console.error(`startRecentAbility failed, code is ${code}, message is ${message}`);
1472    }
1473  }
1474}
1475```
1476## UIAbilityContext.startRecentAbility
1477
1478startRecentAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void
1479
1480Starts an ability with the start options specified. If the ability has multiple instances, the latest instance is started.  This API uses an asynchronous callback to return the result. It can be called only by the main thread.
1481
1482
1483
1484> **NOTE**
1485>
1486> 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).
1487
1488**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1489
1490**System API**: This is a system API.
1491
1492**Parameters**
1493
1494| Name| Type| Mandatory| Description|
1495| -------- | -------- | -------- | -------- |
1496| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
1497| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.|
1498| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
1499
1500**Error codes**
1501
1502For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1503
1504| ID| Error Message|
1505| ------- | -------------------------------- |
1506| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1507| 16000001 | The specified ability does not exist. |
1508| 16000002 | Incorrect ability type. |
1509| 16000004 | Failed to start the invisible ability. |
1510| 16000005 | The specified process does not have the permission. |
1511| 16000006 | Cross-user operations are not allowed. |
1512| 16000008 | The crowdtesting application expires. |
1513| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1514| 16000010 | The call with the continuation flag is forbidden. |
1515| 16000011 | The context does not exist. |
1516| 16000012 | The application is controlled.        |
1517| 16000013 | The application is controlled by EDM.       |
1518| 16000050 | Internal error. |
1519| 16000053 | The ability is not on the top of the UI. |
1520| 16000055 | Installation-free timed out. |
1521| 16000082 | The UIAbility is being started. |
1522| 16200001 | The caller has been released. |
1523| 16000073 | The app clone index is invalid. |
1524
1525**Example**
1526
1527```ts
1528import { UIAbility, Want, StartOptions } from '@kit.AbilityKit';
1529import { BusinessError } from '@kit.BasicServicesKit';
1530
1531export default class EntryAbility extends UIAbility {
1532  onForeground() {
1533    let want: Want = {
1534      deviceId: '',
1535      bundleName: 'com.example.myapplication',
1536      abilityName: 'EntryAbility'
1537    };
1538    let options: StartOptions = {
1539      displayId: 0
1540    };
1541
1542    try {
1543      this.context.startRecentAbility(want, options, (err: BusinessError) => {
1544        if (err.code) {
1545          // Process service logic errors.
1546          console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`);
1547          return;
1548        }
1549        // Carry out normal service processing.
1550        console.info('startRecentAbility succeed');
1551      });
1552    } catch (err) {
1553      // Process input parameter errors.
1554      let code = (err as BusinessError).code;
1555      let message = (err as BusinessError).message;
1556      console.error(`startRecentAbility failed, code is ${code}, message is ${message}`);
1557    }
1558  }
1559}
1560```
1561## UIAbilityContext.startRecentAbility
1562
1563startRecentAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;
1564
1565Starts an ability. If the ability has multiple instances, the latest instance is started. This API uses a promise to return the result. It can be called only by the main thread.
1566
1567> **NOTE**
1568>
1569> 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).
1570
1571**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1572
1573**System API**: This is a system API.
1574
1575**Parameters**
1576
1577| Name| Type| Mandatory| Description|
1578| -------- | -------- | -------- | -------- |
1579| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
1580| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.|
1581
1582**Error codes**
1583
1584For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1585
1586| ID| Error Message|
1587| ------- | -------------------------------- |
1588| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1589| 16000001 | The specified ability does not exist. |
1590| 16000002 | Incorrect ability type. |
1591| 16000004 | Failed to start the invisible ability. |
1592| 16000005 | The specified process does not have the permission. |
1593| 16000006 | Cross-user operations are not allowed. |
1594| 16000008 | The crowdtesting application expires. |
1595| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1596| 16000010 | The call with the continuation flag is forbidden. |
1597| 16000011 | The context does not exist. |
1598| 16000012 | The application is controlled.        |
1599| 16000013 | The application is controlled by EDM.       |
1600| 16000050 | Internal error. |
1601| 16000053 | The ability is not on the top of the UI. |
1602| 16000055 | Installation-free timed out. |
1603| 16000082 | The UIAbility is being started. |
1604| 16200001 | The caller has been released. |
1605| 16000073 | The app clone index is invalid. |
1606
1607**Example**
1608
1609```ts
1610import { UIAbility, Want, StartOptions } from '@kit.AbilityKit';
1611import { BusinessError } from '@kit.BasicServicesKit';
1612
1613export default class EntryAbility extends UIAbility {
1614  onForeground() {
1615    let want: Want = {
1616      bundleName: 'com.example.myapplication',
1617      abilityName: 'EntryAbility'
1618    };
1619    let options: StartOptions = {
1620      displayId: 0,
1621    };
1622
1623    try {
1624      this.context.startRecentAbility(want, options)
1625        .then(() => {
1626          // Carry out normal service processing.
1627          console.info('startRecentAbility succeed');
1628        })
1629        .catch((err: BusinessError) => {
1630          // Process service logic errors.
1631          console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`);
1632        });
1633    } catch (err) {
1634      // Process input parameter errors.
1635      let code = (err as BusinessError).code;
1636      let message = (err as BusinessError).message;
1637      console.error(`startRecentAbility failed, code is ${code}, message is ${message}`);
1638    }
1639  }
1640}
1641```
1642
1643## UIAbilityContext.startAbilityByCallWithAccount<sup>10+</sup>
1644
1645startAbilityByCallWithAccount(want: Want, accountId: number): Promise&lt;Caller&gt;
1646
1647Starts an ability with the account ID specified and obtains the caller object for communicating with the ability. This API can be called only by the main thread.
1648
1649This API cannot be used to start the UIAbility with the launch type set to [specified](../../application-models/uiability-launch-type.md#specified).
1650
1651Observe the following when using this API:
1652 - If an application needs to call this API to start an ability that belongs to another user, it must have the **ohos.permission.ABILITY_BACKGROUND_COMMUNICATION** and **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permissions.
1653 - 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.
1654 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
1655 - The rules for using this API in the same-device and cross-device scenarios are different. For details, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
1656
1657**Required permissions**: ohos.permission.ABILITY_BACKGROUND_COMMUNICATION and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
1658
1659**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1660
1661**System API**: This is a system API.
1662
1663**Parameters**
1664
1665| Name| Type| Mandatory| Description|
1666| -------- | -------- | -------- | -------- |
1667| want | [Want](js-apis-app-ability-want.md) | Yes| Information about the ability to start, including **abilityName**, **moduleName**, **bundleName**, **deviceId** (optional), and **parameters** (optional). If **deviceId** is left blank or null, the local ability is started. If **parameters** is left blank or null, the ability is started in the background.|
1668| accountId | number | Yes| ID of a system account. The value **-1** indicates the current user. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).|
1669
1670**Return value**
1671
1672| Type| Description|
1673| -------- | -------- |
1674| Promise&lt;[Caller](js-apis-app-ability-uiAbility.md#caller)&gt; | Promise used to return the caller object to communicate with.|
1675
1676**Error codes**
1677
1678For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1679
1680| ID| Error Message|
1681| ------- | -------------------------------- |
1682| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1683| 16000001 | The specified ability does not exist. |
1684| 16000002 | Incorrect ability type. |
1685| 16000004 | Failed to start the invisible ability. |
1686| 16000005 | Static permission denied. The specified process does not have the permission. |
1687| 16000006 | Cross-user operations are not allowed. |
1688| 16000008 | The crowdtesting application expires. |
1689| 16000011 | The context does not exist. |
1690| 16000012 | The application is controlled.        |
1691| 16000013 | The application is controlled by EDM.       |
1692| 16000050 | Internal error. |
1693| 16000071 | App clone is not supported. |
1694| 16000072 | App clone or multi-instance is not supported. |
1695| 16000073 | The app clone index is invalid. |
1696| 16000076 | The app instance key is invalid. |
1697| 16000077 | The number of app instances reaches the limit. |
1698| 16000078 | The multi-instance is not supported. |
1699| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
1700| 16000080 | Creating an instance is not supported. |
1701| 16200001 | The caller has been released.        |
1702
1703**Example**
1704
1705```ts
1706import { UIAbility, Want, Caller } from '@kit.AbilityKit';
1707import { BusinessError } from '@kit.BasicServicesKit';
1708
1709export default class EntryAbility extends UIAbility {
1710  onForeground() {
1711    let caller: Caller;
1712    // ID of a system account. The value -1 indicates the current user.
1713    let accountId = -1;
1714    // Specify the ability to start.
1715    let want: Want = {
1716      bundleName: 'com.acts.actscalleeabilityrely',
1717      moduleName: 'entry',
1718      abilityName: 'EntryAbility',
1719      deviceId: '',
1720      parameters: {
1721        // If the value of 'ohos.aafwk.param.callAbilityToForeground' is true, the ability is started in the foreground. If the value is false or not set, the ability is started in the background.
1722        'ohos.aafwk.param.callAbilityToForeground': true
1723      }
1724    };
1725
1726    try {
1727      this.context.startAbilityByCallWithAccount(want, accountId)
1728        .then((obj: Caller) => {
1729          // Carry out normal service processing.
1730          caller = obj;
1731          console.log('startAbilityByCallWithAccount succeed');
1732        }).catch((error: BusinessError) => {
1733        // Process service logic errors.
1734        console.error(`startAbilityByCallWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`);
1735      });
1736    } catch (paramError) {
1737      // Process input parameter errors.
1738      console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
1739    }
1740  }
1741}
1742```
1743
1744## UIAbilityContext.startAbilityAsCaller<sup>10+<sup>
1745
1746startAbilityAsCaller(want: Want, callback: AsyncCallback\<void>): void
1747
1748Starts an ability with the caller information specified. The 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. When 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. This API uses an asynchronous callback to return the result. It can be called only by the main thread.
1749
1750> **NOTE**
1751>
1752> 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).
1753
1754**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1755
1756**System API**: This is a system API.
1757
1758**Parameters**
1759
1760| Name| Type| Mandatory| Description|
1761| -------- | -------- | -------- | -------- |
1762| want | [Want](js-apis-app-ability-want.md)  | Yes| Want information about the target ability.|
1763| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**. Otherwise, **err** is an error object.|
1764
1765**Error codes**
1766
1767For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1768
1769| ID| Error Message|
1770| ------- | -------------------------------- |
1771| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1772| 16000001 | The specified ability does not exist. |
1773| 16000002 | Incorrect ability type. |
1774| 16000004 | Failed to start the invisible ability. |
1775| 16000005 | The specified process does not have the permission. |
1776| 16000006 | Cross-user operations are not allowed. |
1777| 16000008 | The crowdtesting application expires. |
1778| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1779| 16000010 | The call with the continuation flag is forbidden.        |
1780| 16000011 | The context does not exist.        |
1781| 16000012 | The application is controlled.        |
1782| 16000013 | The application is controlled by EDM.       |
1783| 16000050 | Internal error. |
1784| 16000053 | The ability is not on the top of the UI. |
1785| 16000055 | Installation-free timed out. |
1786| 16000071 | App clone is not supported. |
1787| 16000072 | App clone or multi-instance is not supported. |
1788| 16000073 | The app clone index is invalid. |
1789| 16000076 | The app instance key is invalid. |
1790| 16000077 | The number of app instances reaches the limit. |
1791| 16000078 | The multi-instance is not supported. |
1792| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
1793| 16000080 | Creating an instance is not supported. |
1794| 16000082 | The UIAbility is being started. |
1795| 16200001 | The caller has been released. |
1796
1797**Example**
1798
1799```ts
1800import { UIAbility, Want, AbilityConstant } from '@kit.AbilityKit';
1801
1802export default class EntryAbility extends UIAbility {
1803  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
1804    // want contains the information about the caller who starts the application.
1805    let localWant: Want = want;
1806    localWant.bundleName = 'com.example.demo';
1807    localWant.moduleName = 'entry';
1808    localWant.abilityName = 'TestAbility';
1809
1810    // Start a new ability using the caller information.
1811    this.context.startAbilityAsCaller(localWant, (err) => {
1812      if (err && err.code != 0) {
1813        console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err));
1814      } else {
1815        console.log('startAbilityAsCaller success.');
1816      }
1817    })
1818  }
1819}
1820```
1821
1822## UIAbilityContext.startAbilityAsCaller<sup>10+<sup>
1823
1824startAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback\<void>): void
1825
1826Starts an ability with the caller information and start options specified. The 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. When 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. This API uses an asynchronous callback to return the result. It can be called only by the main thread.
1827
1828> **NOTE**
1829>
1830> 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).
1831
1832**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1833
1834**System API**: This is a system API.
1835
1836**Parameters**
1837
1838| Name| Type| Mandatory| Description|
1839| -------- | -------- | -------- | -------- |
1840| want | [Want](js-apis-app-ability-want.md)  | Yes| Want information about the target ability.|
1841| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.|
1842| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**. Otherwise, **err** is an error object.|
1843
1844**Error codes**
1845
1846For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1847
1848| ID| Error Message|
1849| ------- | -------------------------------- |
1850| 401 | 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1851| 16000001 | The specified ability does not exist. |
1852| 16000004 | Failed to start the invisible ability. |
1853| 16000005 | The specified process does not have the permission. |
1854| 16000006 | Cross-user operations are not allowed. |
1855| 16000008 | The crowdtesting application expires. |
1856| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1857| 16000011 | The context does not exist.        |
1858| 16000012 | The application is controlled.        |
1859| 16000013 | The application is controlled by EDM.       |
1860| 16000050 | Internal error. |
1861| 16000053 | The ability is not on the top of the UI. |
1862| 16000055 | Installation-free timed out. |
1863| 16000071 | App clone is not supported. |
1864| 16000072 | App clone or multi-instance is not supported. |
1865| 16000073 | The app clone index is invalid. |
1866| 16000076 | The app instance key is invalid. |
1867| 16000077 | The number of app instances reaches the limit. |
1868| 16000078 | The multi-instance is not supported. |
1869| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
1870| 16000080 | Creating an instance is not supported. |
1871| 16000082 | The UIAbility is being started. |
1872| 16200001 | The caller has been released. |
1873
1874**Example**
1875
1876```ts
1877import { UIAbility, Want, AbilityConstant, StartOptions } from '@kit.AbilityKit';
1878
1879export default class EntryAbility extends UIAbility {
1880  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
1881    // want contains the information about the caller who starts the application.
1882    let localWant: Want = want;
1883    localWant.bundleName = 'com.example.demo';
1884    localWant.moduleName = 'entry';
1885    localWant.abilityName = 'TestAbility';
1886    let option: StartOptions = {
1887      displayId: 0
1888    };
1889
1890    // Start a new ability using the caller information.
1891    this.context.startAbilityAsCaller(localWant, option, (err) => {
1892      if (err && err.code != 0) {
1893        console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err));
1894      } else {
1895        console.log('startAbilityAsCaller success.');
1896      }
1897    })
1898  }
1899}
1900```
1901
1902## UIAbilityContext.startAbilityAsCaller<sup>10+<sup>
1903
1904startAbilityAsCaller(want: Want, options?: StartOptions): Promise\<void>
1905
1906Starts an ability with the caller information specified. The 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. When 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. This API uses a promise to return the result. It can be called only by the main thread.
1907
1908> **NOTE**
1909>
1910> 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).
1911
1912**System capability**: SystemCapability.Ability.AbilityRuntime.Core
1913
1914**System API**: This is a system API.
1915
1916**Parameters**
1917
1918| Name| Type| Mandatory| Description|
1919| -------- | -------- | -------- | -------- |
1920| want | [Want](js-apis-app-ability-want.md)  | Yes| Want information about the target ability.|
1921| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.|
1922
1923**Return value**
1924
1925| Type| Description|
1926| -------- | -------- |
1927| Promise&lt;void&gt; | Promise that returns no value.|
1928
1929**Error codes**
1930
1931For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
1932
1933| ID| Error Message|
1934| ------- | -------------------------------- |
1935| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1936| 16000001 | The specified ability does not exist. |
1937| 16000002 | Incorrect ability type. |
1938| 16000004 | Failed to start the invisible ability. |
1939| 16000005 | The specified process does not have the permission. |
1940| 16000006 | Cross-user operations are not allowed. |
1941| 16000008 | The crowdtesting application expires. |
1942| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1943| 16000010 | The call with the continuation flag is forbidden.        |
1944| 16000011 | The context does not exist.        |
1945| 16000012 | The application is controlled.        |
1946| 16000013 | The application is controlled by EDM.       |
1947| 16000050 | Internal error. |
1948| 16000053 | The ability is not on the top of the UI. |
1949| 16000055 | Installation-free timed out. |
1950| 16000071 | App clone is not supported. |
1951| 16000072 | App clone or multi-instance is not supported. |
1952| 16000073 | The app clone index is invalid. |
1953| 16000076 | The app instance key is invalid. |
1954| 16000077 | The number of app instances reaches the limit. |
1955| 16000078 | The multi-instance is not supported. |
1956| 16000079 | The APP_INSTANCE_KEY cannot be specified. |
1957| 16000080 | Creating an instance is not supported. |
1958| 16000082 | The UIAbility is being started. |
1959| 16200001 | The caller has been released. |
1960
1961**Example**
1962
1963```ts
1964import { UIAbility, Want, AbilityConstant, StartOptions } from '@kit.AbilityKit';
1965import { BusinessError } from '@kit.BasicServicesKit';
1966
1967export default class EntryAbility extends UIAbility {
1968  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
1969    // want contains the information about the caller who starts the application.
1970    let localWant: Want = want;
1971    localWant.bundleName = 'com.example.demo';
1972    localWant.moduleName = 'entry';
1973    localWant.abilityName = 'TestAbility';
1974    let option: StartOptions = {
1975      displayId: 0
1976    };
1977
1978    // Start a new ability using the caller information.
1979    this.context.startAbilityAsCaller(localWant, option)
1980      .then(() => {
1981        console.log('startAbilityAsCaller success.');
1982      })
1983      .catch((err: BusinessError) => {
1984        console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err));
1985      })
1986  }
1987}
1988```
1989
1990## UIAbilityContext.requestModalUIExtension<sup>11+<sup>
1991
1992requestModalUIExtension(pickerWant: Want): Promise\<void>
1993
1994Requests the specified foreground application to start the UIExtensionAbility of the corresponding type. This API uses a promise to return the result. It can be called only by the main thread.
1995
1996The foreground application is specified by **bundleName** in **want.parameters**. If **bundleName** is left unspecified, or if the application specified by **bundleName** is not running in the foreground or does not exist, the UIExtensionAbility is directly started on the system UI. The UIExtensionAbility to start is determined by the combination of the **bundleName**, **abilityName**, and **moduleName** fields in **want**, and its type is determined by the **ability.want.params.uiExtensionType** field in **want.parameters**.
1997
1998Before starting the UIExtensionAbility, ensure that the foreground application has finished page initialization. Otherwise, the UIExtensionAbility fails to start and the error message "uiContent is nullptr" is displayed. The application can determine the time to start the UIExtensionAbility by listening for the page loading status. After the page initialization is successful, the key log information "UIContentImpl: focus again" is recorded.
1999
2000> **NOTE**
2001>
2002> 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).
2003
2004**System capability**: SystemCapability.Ability.AbilityRuntime.Core
2005
2006**System API**: This is a system API.
2007
2008**Parameters**
2009
2010| Name| Type| Mandatory| Description|
2011| -------- | -------- | -------- | -------- |
2012| pickerWant | [Want](js-apis-app-ability-want.md)  | Yes| Want information used to start the UIExtensionAbility.|
2013
2014**Return value**
2015
2016| Type| Description|
2017| -------- | -------- |
2018| Promise&lt;void&gt; | Promise that returns no value.|
2019
2020**Error codes**
2021
2022For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
2023
2024| ID| Error Message|
2025| ------- | -------------------------------- |
2026| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2027| 16000050 | Internal error. |
2028
2029**Example**
2030
2031```ts
2032import { UIAbility, Want } from '@kit.AbilityKit';
2033import { BusinessError } from '@kit.BasicServicesKit';
2034
2035export default class EntryAbility extends UIAbility {
2036  onForeground() {
2037    let want: Want = {
2038      bundleName: 'com.example.myapplication',
2039      abilityName: 'com.example.myapplication.UIExtAbility',
2040      moduleName: 'entry_test',
2041      parameters: {
2042        'bundleName': 'com.example.myapplication',
2043        // The value is the same as the value of type configured for com.example.myapplication.UIExtAbility.
2044        'ability.want.params.uiExtensionType': 'sys/commonUI'
2045      }
2046    };
2047
2048    try {
2049      this.context.requestModalUIExtension(want)
2050        .then(() => {
2051          // Carry out normal service processing.
2052          console.info('requestModalUIExtension succeed');
2053        })
2054        .catch((err: BusinessError) => {
2055          // Process service logic errors.
2056          console.error(`requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`);
2057        });
2058    } catch (err) {
2059      // Process input parameter errors.
2060      let code = (err as BusinessError).code;
2061      let message = (err as BusinessError).message;
2062      console.error(`requestModalUIExtension failed, code is ${code}, message is ${message}`);
2063    }
2064  }
2065}
2066```
2067
2068## UIAbilityContext.requestModalUIExtension<sup>11+<sup>
2069requestModalUIExtension(pickerWant: Want, callback: AsyncCallback\<void>): void
2070
2071Requests the specified foreground application to start the UIExtensionAbility of the corresponding type. This API uses an asynchronous callback to return the result. It can be called only by the main thread.
2072
2073The foreground application is specified by **bundleName** in **want.parameters**. If **bundleName** is left unspecified, or if the application specified by **bundleName** is not running in the foreground or does not exist, the UIExtensionAbility is directly started on the system UI. The UIExtensionAbility to start is determined by the combination of the **bundleName**, **abilityName**, and **moduleName** fields in **want**, and its type is determined by the **ability.want.params.uiExtensionType** field in **want.parameters**.
2074
2075Before starting the UIExtensionAbility, ensure that the foreground application has finished page initialization. Otherwise, the UIExtensionAbility fails to start and the error message "uiContent is nullptr" is displayed. The application can determine the time to start the UIExtensionAbility by listening for the page loading status. After the page initialization is successful, the key log information "UIContentImpl: focus again" is recorded.
2076
2077> **NOTE**
2078>
2079> 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).
2080
2081**System capability**: SystemCapability.Ability.AbilityRuntime.Core
2082
2083**System API**: This is a system API.
2084
2085**Parameters**
2086
2087| Name| Type| Mandatory| Description|
2088| -------- | -------- | -------- | -------- |
2089| pickerWant | [Want](js-apis-app-ability-want.md)  | Yes| Want information used to start the UIExtensionAbility.|
2090| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the UIExtensionAbility is started, **err** is **undefined**; otherwise, **err** is an error object.|
2091
2092**Error codes**
2093
2094For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
2095
2096| ID| Error Message|
2097| ------- | -------------------------------- |
2098| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2099| 16000050 | Internal error. |
2100
2101**Example**
2102
2103```ts
2104import { UIAbility, Want } from '@kit.AbilityKit';
2105import { BusinessError } from '@kit.BasicServicesKit';
2106
2107export default class EntryAbility extends UIAbility {
2108  onForeground() {
2109    let want: Want = {
2110      bundleName: 'com.example.myapplication',
2111      abilityName: 'UIExtAbility',
2112      moduleName: 'entry_test',
2113      parameters: {
2114        'bundleName': 'com.example.myapplication',
2115        // The value is the same as the value of type configured for com.example.myapplication.UIExtAbility.
2116        'ability.want.params.uiExtensionType': 'sys/commonUI'
2117      }
2118    };
2119
2120    try {
2121      this.context.requestModalUIExtension(want, (err: BusinessError) => {
2122        if (err.code) {
2123          // Process service logic errors.
2124          console.error(`requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`);
2125          return;
2126        }
2127        // Carry out normal service processing.
2128        console.info('requestModalUIExtension succeed');
2129      });
2130    } catch (err) {
2131      // Process input parameter errors.
2132      let code = (err as BusinessError).code;
2133      let message = (err as BusinessError).message;
2134      console.error(`requestModalUIExtension failed, code is ${code}, message is ${message}`);
2135    }
2136  }
2137}
2138```
2139