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