1e41f4b71Sopenharmony_ci# AbilityStartCallback 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe AbilityStartCallback module describes the callback invoked to return the UIExtensionAbility startup result. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> The APIs of this module can be used only in the stage model. 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> Since API version 11, the APIs of this module are supported in atomic services. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Modules to Import 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit'; 17e41f4b71Sopenharmony_ci``` 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## onError 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_cionError(code: number, name: string, message: string): void 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciCalled when the UIExtensionAbility fails to start. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Parameters** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 32e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------- | 33e41f4b71Sopenharmony_ci| code | number | Yes | Result code returned when the UIExtensionAbility fails to start. | 34e41f4b71Sopenharmony_ci| name | string | Yes | Name returned when the UIExtensionAbility fails to start. | 35e41f4b71Sopenharmony_ci| message | string | Yes | Error information returned when the UIExtensionAbility fails to start. | 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Example** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci```ts 40e41f4b71Sopenharmony_ciimport { UIAbility, common } from '@kit.AbilityKit'; 41e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 44e41f4b71Sopenharmony_ci onForeground() { 45e41f4b71Sopenharmony_ci let wantParam: Record<string, Object> = { 46e41f4b71Sopenharmony_ci 'time': '2023-10-23 20:45', 47e41f4b71Sopenharmony_ci }; 48e41f4b71Sopenharmony_ci let abilityStartCallback: common.AbilityStartCallback = { 49e41f4b71Sopenharmony_ci onError: (code: number, name: string, message: string) => { 50e41f4b71Sopenharmony_ci console.log(`code:` + code + `name:` + name + `message:` + message); 51e41f4b71Sopenharmony_ci }, 52e41f4b71Sopenharmony_ci onResult: (abilityResult: common.AbilityResult) => { 53e41f4b71Sopenharmony_ci console.log(`resultCode:` + abilityResult.resultCode + `bundleName:` + abilityResult.want?.bundleName); 54e41f4b71Sopenharmony_ci } 55e41f4b71Sopenharmony_ci }; 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci this.context.startAbilityByType("photoEditor", wantParam, abilityStartCallback, (err: BusinessError) => { 58e41f4b71Sopenharmony_ci if (err) { 59e41f4b71Sopenharmony_ci console.error(`startAbilityByType fail, err: ${JSON.stringify(err)}`); 60e41f4b71Sopenharmony_ci } else { 61e41f4b71Sopenharmony_ci console.log(`success`); 62e41f4b71Sopenharmony_ci } 63e41f4b71Sopenharmony_ci }); 64e41f4b71Sopenharmony_ci } 65e41f4b71Sopenharmony_ci} 66e41f4b71Sopenharmony_ci``` 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci## onResult<sup>12+<sup> 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_cionResult?(parameter: AbilityResult): void 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciCalled when the UIExtensionAbility is terminated. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**Parameters** 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 81e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------- | 82e41f4b71Sopenharmony_ci| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes | Result returned when [terminateSelfWithResult](js-apis-inner-application-uiExtensionContext.md#uiextensioncontextterminateselfwithresult12) is called to terminate the UIExtensionAbility. | 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**Example** 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci```ts 87e41f4b71Sopenharmony_ciimport { UIAbility, common } from '@kit.AbilityKit'; 88e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 91e41f4b71Sopenharmony_ci onForeground() { 92e41f4b71Sopenharmony_ci let wantParam: Record<string, Object> = { 93e41f4b71Sopenharmony_ci 'time': '2023-10-23 20:45', 94e41f4b71Sopenharmony_ci }; 95e41f4b71Sopenharmony_ci let abilityStartCallback: common.AbilityStartCallback = { 96e41f4b71Sopenharmony_ci onError: (code: number, name: string, message: string) => { 97e41f4b71Sopenharmony_ci console.log(`code:` + code + `name:` + name + `message:` + message); 98e41f4b71Sopenharmony_ci }, 99e41f4b71Sopenharmony_ci onResult: (abilityResult: common.AbilityResult) => { 100e41f4b71Sopenharmony_ci console.log(`resultCode:` + abilityResult.resultCode + `bundleName:` + abilityResult.want?.bundleName); 101e41f4b71Sopenharmony_ci } 102e41f4b71Sopenharmony_ci }; 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci this.context.startAbilityByType("photoEditor", wantParam, abilityStartCallback, (err: BusinessError) => { 105e41f4b71Sopenharmony_ci if (err) { 106e41f4b71Sopenharmony_ci console.error(`startAbilityByType fail, err: ${JSON.stringify(err)}`); 107e41f4b71Sopenharmony_ci } else { 108e41f4b71Sopenharmony_ci console.log(`success`); 109e41f4b71Sopenharmony_ci } 110e41f4b71Sopenharmony_ci }); 111e41f4b71Sopenharmony_ci } 112e41f4b71Sopenharmony_ci} 113e41f4b71Sopenharmony_ci``` 114