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