• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.appstartup.StartupListener
2
3
4The StartupListener module provides APIs to listen for startup tasks.
5
6> **NOTE**
7>
8> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
9>
10> The APIs of this module can be used only in the stage model.
11
12## Modules to Import
13
14```ts
15import { StartupListener } from '@kit.AbilityKit';
16```
17
18## StartupListener.onCompleted
19
20onCompleted?(error: BusinessError\<void\>): void
21
22Called when all startup tasks are complete.
23
24**System capability**: SystemCapability.Ability.AppStartup
25
26**Parameters**
27
28| Name| Type| Mandatory| Description|
29| -------- | -------- | -------- | -------- |
30| error | [BusinessError](../apis-basic-services-kit/js-apis-base.md#businesserror) | Yes| Error message.|
31
32**Example**
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```
61