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 and cannot be called by third-party applications. 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<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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 and cannot be called by third-party applications. 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 903> **NOTE** 904> 905> 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). 906> Permission verification is not required when **accountId** specifies the current user. 907 908**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 909 910**System capability**: SystemCapability.Ability.AbilityRuntime.Core 911 912**System API**: This is a system API and cannot be called by third-party applications. 913 914**Parameters** 915 916| Name| Type| Mandatory| Description| 917| -------- | -------- | -------- | -------- | 918| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 919| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).| 920| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes| Instance of the callback function after the connection to the ServiceExtensionAbility is set up.| 921 922**Return value** 923 924| Type| Description| 925| -------- | -------- | 926| number | Result code of the ability connection.| 927 928**Error codes** 929 930For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 931 932| ID| Error Message| 933| ------- | -------------------------------- | 934| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 935| 16000001 | The specified ability does not exist. | 936| 16000002 | Incorrect ability type. | 937| 16000004 | Failed to start the invisible ability. | 938| 16000005 | The specified process does not have the permission. | 939| 16000006 | Cross-user operations are not allowed. | 940| 16000008 | The crowdtesting application expires. | 941| 16000053 | The ability is not on the top of the UI. | 942| 16000055 | Installation-free timed out. | 943| 16000011 | The context does not exist. | 944| 16000050 | Internal error. | 945 946**Example** 947 948```ts 949import { UIAbility, Want, common } from '@kit.AbilityKit'; 950import { rpc } from '@kit.IPCKit'; 951import { BusinessError } from '@kit.BasicServicesKit'; 952 953export default class EntryAbility extends UIAbility { 954 onForeground() { 955 let want: Want = { 956 deviceId: '', 957 bundleName: 'com.example.myapplication', 958 abilityName: 'ServiceExtensionAbility' 959 }; 960 let accountId = 100; 961 let commRemote: rpc.IRemoteObject; 962 let options: common.ConnectOptions = { 963 onConnect(elementName, remote) { 964 commRemote = remote; 965 console.info('onConnect...'); 966 }, 967 onDisconnect(elementName) { 968 console.info('onDisconnect...'); 969 }, 970 onFailed(code) { 971 console.info('onFailed...'); 972 } 973 }; 974 let connection: number; 975 976 try { 977 connection = this.context.connectServiceExtensionAbilityWithAccount(want, accountId, options); 978 } catch (err) { 979 // Process input parameter errors. 980 let code = (err as BusinessError).code; 981 let message = (err as BusinessError).message; 982 console.error(`connectServiceExtensionAbility failed, code is ${code}, message is ${message}`); 983 } 984 } 985} 986``` 987 988## UIAbilityContext.startAbilityWithAccount 989 990startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void\>): void 991 992Starts 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. 993 994> **NOTE** 995> 996> 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). 997> Permission verification is not required when **accountId** specifies the current user. 998 999**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1000 1001**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1002 1003**System API**: This is a system API and cannot be called by third-party applications. 1004 1005**Parameters** 1006 1007| Name| Type| Mandatory| Description| 1008| -------- | -------- | -------- | -------- | 1009| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1010| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).| 1011| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 1012 1013**Error codes** 1014 1015For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1016 1017| ID| Error Message| 1018| ------- | -------------------------------- | 1019| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1020| 16000001 | The specified ability does not exist. | 1021| 16000002 | Incorrect ability type. | 1022| 16000004 | Failed to start the invisible ability. | 1023| 16000005 | The specified process does not have the permission. | 1024| 16000006 | Cross-user operations are not allowed. | 1025| 16000008 | The crowdtesting application expires. | 1026| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1027| 16000010 | The call with the continuation flag is forbidden. | 1028| 16000011 | The context does not exist. | 1029| 16000012 | The application is controlled. | 1030| 16000013 | The application is controlled by EDM. | 1031| 16000019 | No matching ability is found. | 1032| 16000050 | Internal error. | 1033| 16000053 | The ability is not on the top of the UI. | 1034| 16000055 | Installation-free timed out. | 1035| 16000071 | App clone is not supported. | 1036| 16000072 | App clone or multi-instance is not supported. | 1037| 16000073 | The app clone index is invalid. | 1038| 16000076 | The app instance key is invalid. | 1039| 16000077 | The number of app instances reaches the limit. | 1040| 16000078 | The multi-instance is not supported. | 1041| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1042| 16000080 | Creating an instance is not supported. | 1043| 16000082 | The UIAbility is being started. | 1044| 16200001 | The caller has been released. | 1045 1046**Example** 1047 1048```ts 1049import { UIAbility, Want } from '@kit.AbilityKit'; 1050import { BusinessError } from '@kit.BasicServicesKit'; 1051 1052export default class EntryAbility extends UIAbility { 1053 onForeground() { 1054 let want: Want = { 1055 deviceId: '', 1056 bundleName: 'com.example.myapplication', 1057 abilityName: 'EntryAbility' 1058 }; 1059 let accountId = 100; 1060 1061 try { 1062 this.context.startAbilityWithAccount(want, accountId, (err: BusinessError) => { 1063 if (err.code) { 1064 // Process service logic errors. 1065 console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`); 1066 return; 1067 } 1068 // Carry out normal service processing. 1069 console.info('startAbilityWithAccount succeed'); 1070 }); 1071 } catch (err) { 1072 // Process input parameter errors. 1073 let code = (err as BusinessError).code; 1074 let message = (err as BusinessError).message; 1075 console.error(`startAbilityWithAccount failed, code is ${code}, message is ${message}`); 1076 } 1077 } 1078} 1079``` 1080 1081 1082## UIAbilityContext.startAbilityWithAccount 1083 1084startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void 1085 1086Starts 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. 1087 1088> **NOTE** 1089> 1090> 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). 1091> Permission verification is not required when **accountId** specifies the current user. 1092 1093**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1094 1095**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1096 1097**System API**: This is a system API and cannot be called by third-party applications. 1098 1099**Parameters** 1100 1101| Name| Type| Mandatory| Description| 1102| -------- | -------- | -------- | -------- | 1103| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1104| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).| 1105| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 1106| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 1107 1108**Error codes** 1109 1110For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1111 1112| ID| Error Message| 1113| ------- | -------------------------------- | 1114| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1115| 16000001 | The specified ability does not exist. | 1116| 16000002 | Incorrect ability type. | 1117| 16000004 | Failed to start the invisible ability. | 1118| 16000005 | The specified process does not have the permission. | 1119| 16000006 | Cross-user operations are not allowed. | 1120| 16000008 | The crowdtesting application expires. | 1121| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1122| 16000010 | The call with the continuation flag is forbidden. | 1123| 16000011 | The context does not exist. | 1124| 16000012 | The application is controlled. | 1125| 16000013 | The application is controlled by EDM. | 1126| 16000019 | No matching ability is found. | 1127| 16000050 | Internal error. | 1128| 16000053 | The ability is not on the top of the UI. | 1129| 16000055 | Installation-free timed out. | 1130| 16000071 | App clone is not supported. | 1131| 16000072 | App clone or multi-instance is not supported. | 1132| 16000073 | The app clone index is invalid. | 1133| 16000076 | The app instance key is invalid. | 1134| 16000077 | The number of app instances reaches the limit. | 1135| 16000078 | The multi-instance is not supported. | 1136| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1137| 16000080 | Creating an instance is not supported. | 1138| 16000082 | The UIAbility is being started. | 1139| 16200001 | The caller has been released. | 1140 1141**Example** 1142 1143```ts 1144import { UIAbility, Want, StartOptions } from '@kit.AbilityKit'; 1145import { BusinessError } from '@kit.BasicServicesKit'; 1146 1147export default class EntryAbility extends UIAbility { 1148 onForeground() { 1149 let want: Want = { 1150 deviceId: '', 1151 bundleName: 'com.example.myapplication', 1152 abilityName: 'EntryAbility' 1153 }; 1154 let accountId = 100; 1155 let options: StartOptions = { 1156 displayId: 0 1157 }; 1158 1159 try { 1160 this.context.startAbilityWithAccount(want, accountId, options, (err: BusinessError) => { 1161 if (err.code) { 1162 // Process service logic errors. 1163 console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`); 1164 return; 1165 } 1166 // Carry out normal service processing. 1167 console.info('startAbilityWithAccount succeed'); 1168 }); 1169 } catch (err) { 1170 // Process input parameter errors. 1171 let code = (err as BusinessError).code; 1172 let message = (err as BusinessError).message; 1173 console.error(`startAbilityWithAccount failed, code is ${code}, message is ${message}`); 1174 } 1175 } 1176} 1177``` 1178 1179 1180## UIAbilityContext.startAbilityWithAccount 1181 1182startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<void\> 1183 1184Starts 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. 1185 1186> **NOTE** 1187> 1188> 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). 1189> Permission verification is not required when **accountId** specifies the current user. 1190 1191**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1192 1193**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1194 1195**System API**: This is a system API and cannot be called by third-party applications. 1196 1197**Parameters** 1198 1199| Name| Type| Mandatory| Description| 1200| -------- | -------- | -------- | -------- | 1201| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1202| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountcount9).| 1203| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 1204 1205**Error codes** 1206 1207For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1208 1209| ID| Error Message| 1210| ------- | -------------------------------- | 1211| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1212| 16000001 | The specified ability does not exist. | 1213| 16000002 | Incorrect ability type. | 1214| 16000004 | Failed to start the invisible ability. | 1215| 16000005 | The specified process does not have the permission. | 1216| 16000006 | Cross-user operations are not allowed. | 1217| 16000008 | The crowdtesting application expires. | 1218| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1219| 16000010 | The call with the continuation flag is forbidden. | 1220| 16000011 | The context does not exist. | 1221| 16000012 | The application is controlled. | 1222| 16000013 | The application is controlled by EDM. | 1223| 16000019 | No matching ability is found. | 1224| 16000050 | Internal error. | 1225| 16000053 | The ability is not on the top of the UI. | 1226| 16000055 | Installation-free timed out. | 1227| 16000071 | App clone is not supported. | 1228| 16000072 | App clone or multi-instance is not supported. | 1229| 16000073 | The app clone index is invalid. | 1230| 16000076 | The app instance key is invalid. | 1231| 16000077 | The number of app instances reaches the limit. | 1232| 16000078 | The multi-instance is not supported. | 1233| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1234| 16000080 | Creating an instance is not supported. | 1235| 16000082 | The UIAbility is being started. | 1236| 16200001 | The caller has been released. | 1237 1238**Example** 1239 1240```ts 1241import { UIAbility, Want, StartOptions } from '@kit.AbilityKit'; 1242import { BusinessError } from '@kit.BasicServicesKit'; 1243 1244export default class EntryAbility extends UIAbility { 1245 onForeground() { 1246 let want: Want = { 1247 deviceId: '', 1248 bundleName: 'com.example.myapplication', 1249 abilityName: 'EntryAbility' 1250 }; 1251 let accountId = 100; 1252 let options: StartOptions = { 1253 displayId: 0 1254 }; 1255 1256 try { 1257 this.context.startAbilityWithAccount(want, accountId, options) 1258 .then(() => { 1259 // Carry out normal service processing. 1260 console.info('startAbilityWithAccount succeed'); 1261 }) 1262 .catch((err: BusinessError) => { 1263 // Process service logic errors. 1264 console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`); 1265 }); 1266 } catch (err) { 1267 // Process input parameter errors. 1268 let code = (err as BusinessError).code; 1269 let message = (err as BusinessError).message; 1270 console.error(`startAbilityWithAccount failed, code is ${code}, message is ${message}`); 1271 } 1272 } 1273} 1274``` 1275 1276## UIAbilityContext.setMissionIcon 1277 1278setMissionIcon(icon: image.PixelMap, callback: AsyncCallback\<void>): void 1279 1280Sets 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. 1281 1282**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1283 1284**System API**: This is a system API and cannot be called by third-party applications. 1285 1286**Parameters** 1287 1288| Name| Type| Mandatory| Description| 1289| -------- | -------- | -------- | -------- | 1290| icon | image.PixelMap | Yes| Icon of the ability to set.| 1291| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 1292 1293**Error codes** 1294 1295For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1296 1297| ID| Error Message| 1298| ------- | -------------------------------- | 1299| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1300| 16000011 | The context does not exist. | 1301| 16000050 | Internal error. | 1302 1303**Example** 1304 1305```ts 1306import { UIAbility } from '@kit.AbilityKit'; 1307import { image } from '@kit.ImageKit'; 1308import { BusinessError } from '@kit.BasicServicesKit'; 1309 1310export default class EntryAbility extends UIAbility { 1311 onForeground() { 1312 let imagePixelMap: image.PixelMap; 1313 let color = new ArrayBuffer(0); 1314 image.createPixelMap(color, { 1315 size: { 1316 height: 100, 1317 width: 100 1318 } 1319 }).then((data) => { 1320 imagePixelMap = data; 1321 this.context.setMissionIcon(imagePixelMap, (err: BusinessError) => { 1322 console.error(`setMissionLabel failed, code is ${err.code}, message is ${err.message}`); 1323 }) 1324 }).catch((err: BusinessError) => { 1325 console.error(`createPixelMap failed, code is ${err.code}, message is ${err.message}`); 1326 }); 1327 } 1328} 1329``` 1330 1331 1332## UIAbilityContext.setMissionIcon 1333 1334setMissionIcon(icon: image.PixelMap): Promise\<void> 1335 1336Sets 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. 1337 1338**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1339 1340**System API**: This is a system API and cannot be called by third-party applications. 1341 1342**Parameters** 1343 1344| Name| Type| Mandatory| Description| 1345| -------- | -------- | -------- | -------- | 1346| icon | image.PixelMap | Yes| Icon of the ability to set.| 1347 1348**Return value** 1349 1350| Type| Description| 1351| -------- | -------- | 1352| Promise<void> | Promise used to return the result.| 1353 1354**Error codes** 1355 1356For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1357 1358| ID| Error Message| 1359| ------- | -------------------------------- | 1360| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1361| 16000011 | The context does not exist. | 1362| 16000050 | Internal error. | 1363 1364**Example** 1365 1366```ts 1367import { UIAbility } from '@kit.AbilityKit'; 1368import { image } from '@kit.ImageKit'; 1369import { BusinessError } from '@kit.BasicServicesKit'; 1370 1371export default class EntryAbility extends UIAbility { 1372 onForeground() { 1373 let imagePixelMap: image.PixelMap; 1374 let color = new ArrayBuffer(0); 1375 image.createPixelMap(color, { 1376 size: { 1377 height: 100, 1378 width: 100 1379 } 1380 }).then((data) => { 1381 imagePixelMap = data; 1382 this.context.setMissionIcon(imagePixelMap) 1383 .then(() => { 1384 console.info('setMissionIcon succeed'); 1385 }) 1386 .catch((err: BusinessError) => { 1387 console.error(`setMissionLabel failed, code is ${err.code}, message is ${err.message}`); 1388 }); 1389 }).catch((err: BusinessError) => { 1390 console.error(`createPixelMap failed, code is ${err.code}, message is ${err.message}`); 1391 }); 1392 } 1393} 1394``` 1395 1396## UIAbilityContext.startRecentAbility 1397 1398startRecentAbility(want: Want, callback: AsyncCallback<void>): void 1399 1400Starts 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. 1401 1402> **NOTE** 1403> 1404> 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). 1405 1406**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1407 1408**System API**: This is a system API and cannot be called by third-party applications. 1409 1410**Parameters** 1411 1412| Name| Type| Mandatory| Description| 1413| -------- | -------- | -------- | -------- | 1414| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1415| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 1416 1417**Error codes** 1418 1419For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1420 1421| ID| Error Message| 1422| ------- | -------------------------------- | 1423| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1424| 16000001 | The specified ability does not exist. | 1425| 16000002 | Incorrect ability type. | 1426| 16000004 | Failed to start the invisible ability. | 1427| 16000005 | The specified process does not have the permission. | 1428| 16000006 | Cross-user operations are not allowed. | 1429| 16000008 | The crowdtesting application expires. | 1430| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1431| 16000010 | The call with the continuation flag is forbidden. | 1432| 16000011 | The context does not exist. | 1433| 16000012 | The application is controlled. | 1434| 16000013 | The application is controlled by EDM. | 1435| 16000050 | Internal error. | 1436| 16000053 | The ability is not on the top of the UI. | 1437| 16000055 | Installation-free timed out. | 1438| 16000082 | The UIAbility is being started. | 1439| 16200001 | The caller has been released. | 1440| 16000073 | The app clone index is invalid. | 1441 1442**Example** 1443 1444```ts 1445import { UIAbility, Want } from '@kit.AbilityKit'; 1446import { BusinessError } from '@kit.BasicServicesKit'; 1447 1448export default class EntryAbility extends UIAbility { 1449 onForeground() { 1450 let want: Want = { 1451 bundleName: 'com.example.myapplication', 1452 abilityName: 'EntryAbility' 1453 }; 1454 1455 try { 1456 this.context.startRecentAbility(want, (err: BusinessError) => { 1457 if (err.code) { 1458 // Process service logic errors. 1459 console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); 1460 return; 1461 } 1462 // Carry out normal service processing. 1463 console.info('startRecentAbility succeed'); 1464 }); 1465 } catch (err) { 1466 // Process input parameter errors. 1467 let code = (err as BusinessError).code; 1468 let message = (err as BusinessError).message; 1469 console.error(`startRecentAbility failed, code is ${code}, message is ${message}`); 1470 } 1471 } 1472} 1473``` 1474## UIAbilityContext.startRecentAbility 1475 1476startRecentAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void 1477 1478Starts 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. 1479 1480 1481 1482> **NOTE** 1483> 1484> 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). 1485 1486**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1487 1488**System API**: This is a system API and cannot be called by third-party applications. 1489 1490**Parameters** 1491 1492| Name| Type| Mandatory| Description| 1493| -------- | -------- | -------- | -------- | 1494| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1495| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 1496| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 1497 1498**Error codes** 1499 1500For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1501 1502| ID| Error Message| 1503| ------- | -------------------------------- | 1504| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1505| 16000001 | The specified ability does not exist. | 1506| 16000002 | Incorrect ability type. | 1507| 16000004 | Failed to start the invisible ability. | 1508| 16000005 | The specified process does not have the permission. | 1509| 16000006 | Cross-user operations are not allowed. | 1510| 16000008 | The crowdtesting application expires. | 1511| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1512| 16000010 | The call with the continuation flag is forbidden. | 1513| 16000011 | The context does not exist. | 1514| 16000012 | The application is controlled. | 1515| 16000013 | The application is controlled by EDM. | 1516| 16000050 | Internal error. | 1517| 16000053 | The ability is not on the top of the UI. | 1518| 16000055 | Installation-free timed out. | 1519| 16000082 | The UIAbility is being started. | 1520| 16200001 | The caller has been released. | 1521| 16000073 | The app clone index is invalid. | 1522 1523**Example** 1524 1525```ts 1526import { UIAbility, Want, StartOptions } from '@kit.AbilityKit'; 1527import { BusinessError } from '@kit.BasicServicesKit'; 1528 1529export default class EntryAbility extends UIAbility { 1530 onForeground() { 1531 let want: Want = { 1532 deviceId: '', 1533 bundleName: 'com.example.myapplication', 1534 abilityName: 'EntryAbility' 1535 }; 1536 let options: StartOptions = { 1537 displayId: 0 1538 }; 1539 1540 try { 1541 this.context.startRecentAbility(want, options, (err: BusinessError) => { 1542 if (err.code) { 1543 // Process service logic errors. 1544 console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); 1545 return; 1546 } 1547 // Carry out normal service processing. 1548 console.info('startRecentAbility succeed'); 1549 }); 1550 } catch (err) { 1551 // Process input parameter errors. 1552 let code = (err as BusinessError).code; 1553 let message = (err as BusinessError).message; 1554 console.error(`startRecentAbility failed, code is ${code}, message is ${message}`); 1555 } 1556 } 1557} 1558``` 1559## UIAbilityContext.startRecentAbility 1560 1561startRecentAbility(want: Want, options?: StartOptions): Promise<void> 1562 1563Starts 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. 1564 1565> **NOTE** 1566> 1567> 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). 1568 1569**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1570 1571**System API**: This is a system API and cannot be called by third-party applications. 1572 1573**Parameters** 1574 1575| Name| Type| Mandatory| Description| 1576| -------- | -------- | -------- | -------- | 1577| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1578| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 1579 1580**Error codes** 1581 1582For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1583 1584| ID| Error Message| 1585| ------- | -------------------------------- | 1586| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1587| 16000001 | The specified ability does not exist. | 1588| 16000002 | Incorrect ability type. | 1589| 16000004 | Failed to start the invisible ability. | 1590| 16000005 | The specified process does not have the permission. | 1591| 16000006 | Cross-user operations are not allowed. | 1592| 16000008 | The crowdtesting application expires. | 1593| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1594| 16000010 | The call with the continuation flag is forbidden. | 1595| 16000011 | The context does not exist. | 1596| 16000012 | The application is controlled. | 1597| 16000013 | The application is controlled by EDM. | 1598| 16000050 | Internal error. | 1599| 16000053 | The ability is not on the top of the UI. | 1600| 16000055 | Installation-free timed out. | 1601| 16000082 | The UIAbility is being started. | 1602| 16200001 | The caller has been released. | 1603| 16000073 | The app clone index is invalid. | 1604 1605**Example** 1606 1607```ts 1608import { UIAbility, Want, StartOptions } from '@kit.AbilityKit'; 1609import { BusinessError } from '@kit.BasicServicesKit'; 1610 1611export default class EntryAbility extends UIAbility { 1612 onForeground() { 1613 let want: Want = { 1614 bundleName: 'com.example.myapplication', 1615 abilityName: 'EntryAbility' 1616 }; 1617 let options: StartOptions = { 1618 displayId: 0, 1619 }; 1620 1621 try { 1622 this.context.startRecentAbility(want, options) 1623 .then(() => { 1624 // Carry out normal service processing. 1625 console.info('startRecentAbility succeed'); 1626 }) 1627 .catch((err: BusinessError) => { 1628 // Process service logic errors. 1629 console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); 1630 }); 1631 } catch (err) { 1632 // Process input parameter errors. 1633 let code = (err as BusinessError).code; 1634 let message = (err as BusinessError).message; 1635 console.error(`startRecentAbility failed, code is ${code}, message is ${message}`); 1636 } 1637 } 1638} 1639``` 1640 1641## UIAbilityContext.startAbilityByCallWithAccount<sup>10+</sup> 1642 1643startAbilityByCallWithAccount(want: Want, accountId: number): Promise<Caller> 1644 1645Starts 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. 1646 1647This API cannot be used to start the UIAbility with the launch type set to [specified](../../application-models/uiability-launch-type.md#specified). 1648 1649Observe the following when using this API: 1650 - 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. 1651 - 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. 1652 - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 1653 - 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). 1654 1655**Required permissions**: ohos.permission.ABILITY_BACKGROUND_COMMUNICATION and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1656 1657**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1658 1659**System API**: This is a system API and cannot be called by third-party applications. 1660 1661**Parameters** 1662 1663| Name| Type| Mandatory| Description| 1664| -------- | -------- | -------- | -------- | 1665| 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.| 1666| 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).| 1667 1668**Return value** 1669 1670| Type| Description| 1671| -------- | -------- | 1672| Promise<[Caller](js-apis-app-ability-uiAbility.md#caller)> | Promise used to return the caller object to communicate with.| 1673 1674**Error codes** 1675 1676For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1677 1678| ID| Error Message| 1679| ------- | -------------------------------- | 1680| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1681| 16000001 | The specified ability does not exist. | 1682| 16000002 | Incorrect ability type. | 1683| 16000004 | Failed to start the invisible ability. | 1684| 16000005 | Static permission denied. The specified process does not have the permission. | 1685| 16000006 | Cross-user operations are not allowed. | 1686| 16000008 | The crowdtesting application expires. | 1687| 16000011 | The context does not exist. | 1688| 16000012 | The application is controlled. | 1689| 16000013 | The application is controlled by EDM. | 1690| 16000050 | Internal error. | 1691| 16000071 | App clone is not supported. | 1692| 16000072 | App clone or multi-instance is not supported. | 1693| 16000073 | The app clone index is invalid. | 1694| 16000076 | The app instance key is invalid. | 1695| 16000077 | The number of app instances reaches the limit. | 1696| 16000078 | The multi-instance is not supported. | 1697| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1698| 16000080 | Creating an instance is not supported. | 1699| 16200001 | The caller has been released. | 1700 1701**Example** 1702 1703```ts 1704import { UIAbility, Want, Caller } from '@kit.AbilityKit'; 1705import { BusinessError } from '@kit.BasicServicesKit'; 1706 1707export default class EntryAbility extends UIAbility { 1708 onForeground() { 1709 let caller: Caller; 1710 // ID of a system account. The value -1 indicates the current user. 1711 let accountId = -1; 1712 // Specify the ability to start. 1713 let want: Want = { 1714 bundleName: 'com.acts.actscalleeabilityrely', 1715 moduleName: 'entry', 1716 abilityName: 'EntryAbility', 1717 deviceId: '', 1718 parameters: { 1719 // 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. 1720 'ohos.aafwk.param.callAbilityToForeground': true 1721 } 1722 }; 1723 1724 try { 1725 this.context.startAbilityByCallWithAccount(want, accountId) 1726 .then((obj: Caller) => { 1727 // Carry out normal service processing. 1728 caller = obj; 1729 console.log('startAbilityByCallWithAccount succeed'); 1730 }).catch((error: BusinessError) => { 1731 // Process service logic errors. 1732 console.error(`startAbilityByCallWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 1733 }); 1734 } catch (paramError) { 1735 // Process input parameter errors. 1736 console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`); 1737 } 1738 } 1739} 1740``` 1741 1742## UIAbilityContext.startAbilityAsCaller<sup>10+<sup> 1743 1744startAbilityAsCaller(want: Want, callback: AsyncCallback\<void>): void 1745 1746Starts 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. 1747 1748> **NOTE** 1749> 1750> 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). 1751 1752**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1753 1754**System API**: This is a system API and cannot be called by third-party applications. 1755 1756**Parameters** 1757 1758| Name| Type| Mandatory| Description| 1759| -------- | -------- | -------- | -------- | 1760| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1761| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**. Otherwise, **err** is an error object.| 1762 1763**Error codes** 1764 1765For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1766 1767| ID| Error Message| 1768| ------- | -------------------------------- | 1769| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1770| 16000001 | The specified ability does not exist. | 1771| 16000002 | Incorrect ability type. | 1772| 16000004 | Failed to start the invisible ability. | 1773| 16000005 | The specified process does not have the permission. | 1774| 16000006 | Cross-user operations are not allowed. | 1775| 16000008 | The crowdtesting application expires. | 1776| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1777| 16000010 | The call with the continuation flag is forbidden. | 1778| 16000011 | The context does not exist. | 1779| 16000012 | The application is controlled. | 1780| 16000013 | The application is controlled by EDM. | 1781| 16000050 | Internal error. | 1782| 16000053 | The ability is not on the top of the UI. | 1783| 16000055 | Installation-free timed out. | 1784| 16000071 | App clone is not supported. | 1785| 16000072 | App clone or multi-instance is not supported. | 1786| 16000073 | The app clone index is invalid. | 1787| 16000076 | The app instance key is invalid. | 1788| 16000077 | The number of app instances reaches the limit. | 1789| 16000078 | The multi-instance is not supported. | 1790| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1791| 16000080 | Creating an instance is not supported. | 1792| 16000082 | The UIAbility is being started. | 1793| 16200001 | The caller has been released. | 1794 1795**Example** 1796 1797```ts 1798import { UIAbility, Want, AbilityConstant } from '@kit.AbilityKit'; 1799 1800export default class EntryAbility extends UIAbility { 1801 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 1802 // want contains the information about the caller who starts the application. 1803 let localWant: Want = want; 1804 localWant.bundleName = 'com.example.demo'; 1805 localWant.moduleName = 'entry'; 1806 localWant.abilityName = 'TestAbility'; 1807 1808 // Start a new ability using the caller information. 1809 this.context.startAbilityAsCaller(localWant, (err) => { 1810 if (err && err.code != 0) { 1811 console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); 1812 } else { 1813 console.log('startAbilityAsCaller success.'); 1814 } 1815 }) 1816 } 1817} 1818``` 1819 1820## UIAbilityContext.startAbilityAsCaller<sup>10+<sup> 1821 1822startAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback\<void>): void 1823 1824Starts 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. 1825 1826> **NOTE** 1827> 1828> 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). 1829**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1830 1831**System API**: This is a system API and cannot be called by third-party applications. 1832 1833**Parameters** 1834 1835| Name| Type| Mandatory| Description| 1836| -------- | -------- | -------- | -------- | 1837| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1838| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 1839| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**. Otherwise, **err** is an error object.| 1840 1841**Error codes** 1842 1843For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1844 1845| ID| Error Message| 1846| ------- | -------------------------------- | 1847| 401 | 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1848| 16000001 | The specified ability does not exist. | 1849| 16000004 | Failed to start the invisible ability. | 1850| 16000005 | The specified process does not have the permission. | 1851| 16000006 | Cross-user operations are not allowed. | 1852| 16000008 | The crowdtesting application expires. | 1853| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1854| 16000011 | The context does not exist. | 1855| 16000012 | The application is controlled. | 1856| 16000013 | The application is controlled by EDM. | 1857| 16000050 | Internal error. | 1858| 16000053 | The ability is not on the top of the UI. | 1859| 16000055 | Installation-free timed out. | 1860| 16000071 | App clone is not supported. | 1861| 16000072 | App clone or multi-instance is not supported. | 1862| 16000073 | The app clone index is invalid. | 1863| 16000076 | The app instance key is invalid. | 1864| 16000077 | The number of app instances reaches the limit. | 1865| 16000078 | The multi-instance is not supported. | 1866| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1867| 16000080 | Creating an instance is not supported. | 1868| 16000082 | The UIAbility is being started. | 1869| 16200001 | The caller has been released. | 1870 1871**Example** 1872 1873```ts 1874import { UIAbility, Want, AbilityConstant, StartOptions } from '@kit.AbilityKit'; 1875 1876export default class EntryAbility extends UIAbility { 1877 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 1878 // want contains the information about the caller who starts the application. 1879 let localWant: Want = want; 1880 localWant.bundleName = 'com.example.demo'; 1881 localWant.moduleName = 'entry'; 1882 localWant.abilityName = 'TestAbility'; 1883 let option: StartOptions = { 1884 displayId: 0 1885 }; 1886 1887 // Start a new ability using the caller information. 1888 this.context.startAbilityAsCaller(localWant, option, (err) => { 1889 if (err && err.code != 0) { 1890 console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); 1891 } else { 1892 console.log('startAbilityAsCaller success.'); 1893 } 1894 }) 1895 } 1896} 1897``` 1898 1899## UIAbilityContext.startAbilityAsCaller<sup>10+<sup> 1900 1901startAbilityAsCaller(want: Want, options?: StartOptions): Promise\<void> 1902 1903Starts 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. 1904 1905> **NOTE** 1906> 1907> 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). 1908 1909**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1910 1911**System API**: This is a system API and cannot be called by third-party applications. 1912 1913**Parameters** 1914 1915| Name| Type| Mandatory| Description| 1916| -------- | -------- | -------- | -------- | 1917| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1918| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 1919 1920**Return value** 1921 1922| Type| Description| 1923| -------- | -------- | 1924| Promise<void> | Promise that returns no value.| 1925 1926**Error codes** 1927 1928For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1929 1930| ID| Error Message| 1931| ------- | -------------------------------- | 1932| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1933| 16000001 | The specified ability does not exist. | 1934| 16000002 | Incorrect ability type. | 1935| 16000004 | Failed to start the invisible ability. | 1936| 16000005 | The specified process does not have the permission. | 1937| 16000006 | Cross-user operations are not allowed. | 1938| 16000008 | The crowdtesting application expires. | 1939| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1940| 16000010 | The call with the continuation flag is forbidden. | 1941| 16000011 | The context does not exist. | 1942| 16000012 | The application is controlled. | 1943| 16000013 | The application is controlled by EDM. | 1944| 16000050 | Internal error. | 1945| 16000053 | The ability is not on the top of the UI. | 1946| 16000055 | Installation-free timed out. | 1947| 16000071 | App clone is not supported. | 1948| 16000072 | App clone or multi-instance is not supported. | 1949| 16000073 | The app clone index is invalid. | 1950| 16000076 | The app instance key is invalid. | 1951| 16000077 | The number of app instances reaches the limit. | 1952| 16000078 | The multi-instance is not supported. | 1953| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1954| 16000080 | Creating an instance is not supported. | 1955| 16000082 | The UIAbility is being started. | 1956| 16200001 | The caller has been released. | 1957 1958**Example** 1959 1960```ts 1961import { UIAbility, Want, AbilityConstant, StartOptions } from '@kit.AbilityKit'; 1962import { BusinessError } from '@kit.BasicServicesKit'; 1963 1964export default class EntryAbility extends UIAbility { 1965 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 1966 // want contains the information about the caller who starts the application. 1967 let localWant: Want = want; 1968 localWant.bundleName = 'com.example.demo'; 1969 localWant.moduleName = 'entry'; 1970 localWant.abilityName = 'TestAbility'; 1971 let option: StartOptions = { 1972 displayId: 0 1973 }; 1974 1975 // Start a new ability using the caller information. 1976 this.context.startAbilityAsCaller(localWant, option) 1977 .then(() => { 1978 console.log('startAbilityAsCaller success.'); 1979 }) 1980 .catch((err: BusinessError) => { 1981 console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); 1982 }) 1983 } 1984} 1985``` 1986 1987## UIAbilityContext.requestModalUIExtension<sup>11+<sup> 1988 1989requestModalUIExtension(pickerWant: Want): Promise\<void> 1990 1991Requests 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. 1992 1993The 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**. 1994 1995Before 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. 1996 1997> **NOTE** 1998> 1999> 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). 2000 2001**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2002 2003**System API**: This is a system API. 2004 2005**Parameters** 2006 2007| Name| Type| Mandatory| Description| 2008| -------- | -------- | -------- | -------- | 2009| pickerWant | [Want](js-apis-app-ability-want.md) | Yes| Want information used to start the UIExtensionAbility.| 2010 2011**Return value** 2012 2013| Type| Description| 2014| -------- | -------- | 2015| Promise<void> | Promise that returns no value.| 2016 2017**Error codes** 2018 2019For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2020 2021| ID| Error Message| 2022| ------- | -------------------------------- | 2023| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2024| 16000050 | Internal error. | 2025 2026**Example** 2027 2028```ts 2029import { UIAbility, Want } from '@kit.AbilityKit'; 2030import { BusinessError } from '@kit.BasicServicesKit'; 2031 2032export default class EntryAbility extends UIAbility { 2033 onForeground() { 2034 let want: Want = { 2035 bundleName: 'com.example.myapplication', 2036 abilityName: 'com.example.myapplication.UIExtAbility', 2037 moduleName: 'entry_test', 2038 parameters: { 2039 'bundleName': 'com.example.myapplication', 2040 // The value is the same as the value of type configured for com.example.myapplication.UIExtAbility. 2041 'ability.want.params.uiExtensionType': 'sys/commonUI' 2042 } 2043 }; 2044 2045 try { 2046 this.context.requestModalUIExtension(want) 2047 .then(() => { 2048 // Carry out normal service processing. 2049 console.info('requestModalUIExtension succeed'); 2050 }) 2051 .catch((err: BusinessError) => { 2052 // Process service logic errors. 2053 console.error(`requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`); 2054 }); 2055 } catch (err) { 2056 // Process input parameter errors. 2057 let code = (err as BusinessError).code; 2058 let message = (err as BusinessError).message; 2059 console.error(`requestModalUIExtension failed, code is ${code}, message is ${message}`); 2060 } 2061 } 2062} 2063``` 2064 2065## UIAbilityContext.requestModalUIExtension<sup>11+<sup> 2066requestModalUIExtension(pickerWant: Want, callback: AsyncCallback\<void>): void 2067 2068Requests 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. 2069 2070The 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**. 2071 2072Before 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. 2073 2074> **NOTE** 2075> 2076> 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). 2077**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2078 2079**System API**: This is a system API. 2080 2081**Parameters** 2082 2083| Name| Type| Mandatory| Description| 2084| -------- | -------- | -------- | -------- | 2085| pickerWant | [Want](js-apis-app-ability-want.md) | Yes| Want information used to start the UIExtensionAbility.| 2086| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the UIExtensionAbility is started, **err** is **undefined**; otherwise, **err** is an error object.| 2087 2088**Error codes** 2089 2090For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2091 2092| ID| Error Message| 2093| ------- | -------------------------------- | 2094| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2095| 16000050 | Internal error. | 2096 2097**Example** 2098 2099```ts 2100import { UIAbility, Want } from '@kit.AbilityKit'; 2101import { BusinessError } from '@kit.BasicServicesKit'; 2102 2103export default class EntryAbility extends UIAbility { 2104 onForeground() { 2105 let want: Want = { 2106 bundleName: 'com.example.myapplication', 2107 abilityName: 'UIExtAbility', 2108 moduleName: 'entry_test', 2109 parameters: { 2110 'bundleName': 'com.example.myapplication', 2111 // The value is the same as the value of type configured for com.example.myapplication.UIExtAbility. 2112 'ability.want.params.uiExtensionType': 'sys/commonUI' 2113 } 2114 }; 2115 2116 try { 2117 this.context.requestModalUIExtension(want, (err: BusinessError) => { 2118 if (err.code) { 2119 // Process service logic errors. 2120 console.error(`requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`); 2121 return; 2122 } 2123 // Carry out normal service processing. 2124 console.info('requestModalUIExtension succeed'); 2125 }); 2126 } catch (err) { 2127 // Process input parameter errors. 2128 let code = (err as BusinessError).code; 2129 let message = (err as BusinessError).message; 2130 console.error(`requestModalUIExtension failed, code is ${code}, message is ${message}`); 2131 } 2132 } 2133} 2134``` 2135