@ohos.app.appstartup.StartupConfig (AppStartup Configuration)

The module defines the configuration of AppStartup.

NOTE

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.

The APIs of this module can be used only in the stage model.

Modules to Import

import { StartupConfig } from '@kit.AbilityKit';

StartupConfig

Describes the timeout duration and listener of startup tasks in AppStartup. For details, see Setting Startup Parameters.

System capability: SystemCapability.Ability.AppStartup

Name Type Read Only Optional Description
timeoutMs number No Yes Timeout for executing all startup tasks, measured in ms. The default value is 10000 ms.
startupListener StartupListener No Yes AppStartup listener, which is called when all the startup tasks are complete.

Example

import { StartupConfig, StartupConfigEntry, StartupListener } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

export default class MyStartupConfigEntry extends StartupConfigEntry {
  onConfig() {
    hilog.info(0x0000, 'testTag', `onConfig`);
    let onCompletedCallback = (error: BusinessError<void>) => {
      hilog.info(0x0000, 'testTag', `onCompletedCallback`);
      if (error) {
        hilog.error(0x0000, 'testTag', 'onCompletedCallback: %{public}d, message: %{public}s', error.code,
          error.message);
      } else {
        hilog.info(0x0000, 'testTag', `onCompletedCallback: success.`);
      }
    };
    let startupListener: StartupListener = {
      'onCompleted': onCompletedCallback
    };
    let config: StartupConfig = {
      'timeoutMs': 10000,
      'startupListener': startupListener
    };
    return config;
  }
}