1# @ohos.app.appstartup.StartupListener
2
3
4本模块提供监听启动任务的能力。
5
6> **说明:**
7>
8> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
9>
10> 本模块接口仅可在Stage模型下使用。
11
12## 导入模块
13
14```ts
15import { StartupListener } from '@kit.AbilityKit';
16```
17
18## StartupListener.onCompleted
19
20onCompleted?(error: BusinessError\<void\>): void
21
22在所有启动任务完成时调用。
23
24**系统能力**:SystemCapability.Ability.AppStartup
25
26**参数:**
27
28| 参数名 | 类型 | 必填 | 说明 |
29| -------- | -------- | -------- | -------- |
30| error | [BusinessError](../apis-basic-services-kit/js-apis-base.md#businesserror) | 是 | 错误信息。 |
31
32**示例:**
33
34```ts
35import { StartupConfig, StartupConfigEntry, StartupListener } from '@kit.AbilityKit';
36import { BusinessError } from '@kit.BasicServicesKit';
37import { hilog } from '@kit.PerformanceAnalysisKit';
38
39export default class MyStartupConfigEntry extends StartupConfigEntry {
40  onConfig() {
41    hilog.info(0x0000, 'testTag', `onConfig`);
42    let onCompletedCallback = (error: BusinessError<void>) => {
43      hilog.info(0x0000, 'testTag', `onCompletedCallback`);
44      if (error) {
45        hilog.info(0x0000, 'testTag', 'onCompletedCallback: %{public}d, message: %{public}s', error.code, error.message);
46      } else {
47        hilog.info(0x0000, 'testTag', `onCompletedCallback: success.`);
48      }
49    }
50    let startupListener: StartupListener = {
51      'onCompleted': onCompletedCallback
52    }
53    let config: StartupConfig = {
54      'timeoutMs': 10000,
55      'startupListener': startupListener
56    }
57    return config;
58  }
59}
60```