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