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