• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.appstartup.StartupConfig (Startup Task Configuration)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @yzkp-->
5<!--Designer: @yzkp-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9The module provides APIs for startup task configuration.
10
11> **NOTE**
12>
13> 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.
14>
15> The APIs of this module can be used only in the stage model.
16
17## Modules to Import
18
19```js
20import { StartupConfig } from '@kit.AbilityKit';
21```
22
23## StartupConfig
24
25**System capability**: SystemCapability.Ability.AppStartup
26
27| Name| Type| Read Only| Optional| Description|
28| -------- | -------- | -------- | -------- | -------- |
29| timeoutMs | number | No| Yes| Timeout for executing all startup tasks, measured in ms. The default value is 10000 ms.|
30| startupListener | [StartupListener](./js-apis-app-appstartup-startupListener.md) | No| Yes| AppStartup listener, which is called when all the startup tasks are complete.|
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.error(0x0000, 'testTag', 'onCompletedCallback: %{public}d, message: %{public}s', error.code,
46          error.message);
47      } else {
48        hilog.info(0x0000, 'testTag', `onCompletedCallback: success.`);
49      }
50    };
51    let startupListener: StartupListener = {
52      'onCompleted': onCompletedCallback
53    };
54    let config: StartupConfig = {
55      'timeoutMs': 10000,
56      'startupListener': startupListener
57    };
58    return config;
59  }
60}
61```
62