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