55a280c3创建于 2025年12月12日历史提交

@ohos.app.appstartup.StartupTask (AppStartup Task)

The module provides capabilities related to startup tasks in 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 { StartupTask } from '@kit.AbilityKit';

StartupTask

Provides capabilities related to startup tasks. It is decorated by @Sendable.

Decorator: @Sendable

onDependencyCompleted

onDependencyCompleted?(dependency: string, result: Object): void

Called when the dependent startup task is complete.

System capability: SystemCapability.Ability.AppStartup

Parameters

Name Type Mandatory Description
dependency string Yes Name of the dependent startup task.
result Object Yes Execution result of init of the dependent startup task.

Example

import { StartupTask, common } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

@Sendable
export default class StartupTask_001 extends StartupTask {
  constructor() {
    super();
  }

  async init(context: common.AbilityStageContext) {
    // ...
  }

  onDependencyCompleted(dependency: string, result: Object): void {
    hilog.info(0x0000, 'testTag', 'StartupTask_001 onDependencyCompleted, dependency: %{public}s, result: %{public}s',
      dependency, JSON.stringify(result));
    // ...
  }
}

init

init(context: AbilityStageContext): Promise<Object | void>

Called when all the dependent startup tasks are complete. You can initialize the startup task in this callback. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AppStartup

Parameters

Name Type Mandatory Description
context AbilityStageContext Yes Context environment of the AbilityStage.

Return value

Type Description
Promise<Object | void> Promise used to return the execution result.

Example

import { StartupTask, common } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

@Sendable
export default class StartupTask_001 extends StartupTask {
  constructor() {
    super();
  }
  async init(context: common.AbilityStageContext) {
    hilog.info(0x0000, 'testTag', 'StartupTask_001 init.');
    // ...
    
    return "StartupTask_001";
  }

  onDependencyCompleted(dependency: string, result: Object): void {
    // ...
  }
}