1e41f4b71Sopenharmony_ci# AbilityStartCallback
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci定义拉起UIExtensionAbility执行结果的回调。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> 
9e41f4b71Sopenharmony_ci> 本模块接口仅可在Stage模型下使用。
10e41f4b71Sopenharmony_ci> 
11e41f4b71Sopenharmony_ci> 从API version 11开始,本模块接口支持在原子化服务中使用。
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## 导入模块
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_ci拉起UIExtensionAbility执行失败的回调。
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**参数:**
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| 参数名       | 类型                     | 必填   | 说明            |
32e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------- |
33e41f4b71Sopenharmony_ci| code | number | 是    | 拉起UIExtensionAbility执行失败时返回的结果码。 |
34e41f4b71Sopenharmony_ci| name | string | 是    | 拉起UIExtensionAbility执行失败时返回的名称。 |
35e41f4b71Sopenharmony_ci| message | string | 是    | 拉起UIExtensionAbility执行失败时返回的错误信息。 |
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**示例:**
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_ci拉起UIExtensionAbility终止时的回调。
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**参数:**
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| 参数名       | 类型                     | 必填   | 说明            |
81e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------- |
82e41f4b71Sopenharmony_ci| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | 是    | 当调用[terminateSelfWithResult](js-apis-inner-application-uiExtensionContext.md#uiextensioncontextterminateselfwithresult12)方法终止UIExtensionAbility时返回的结果。 |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**示例:**
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