openharmony 鸿蒙 js-apis-WorkSchedulerExtensionAbility

2025-06-12 浏览 (1)

@ohos.WorkSchedulerExtensionAbility (Deferred Task Scheduling Callbacks)

The WorkSchedulerExtensionAbility module provides callbacks for deferred task scheduling. You can override the APIs provided by this module. When a deferred task is triggered, the system calls back the application through the APIs and processes the task logic in the callback.

NOTE

  • The initial APIs of this module are supported since API version 9. 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 { WorkSchedulerExtensionAbility } from '@kit.BackgroundTasksKit';

WorkSchedulerExtensionContext10+

type WorkSchedulerExtensionContext = _WorkSchedulerExtensionContext

System capability: SystemCapability.ResourceSchedule.WorkScheduler

TypeDescription
_WorkSchedulerExtensionContextContext of the WorkSchedulerExtensionAbility.

WorkSchedulerExtensionAbility

Properties

System capability: SystemCapability.ResourceSchedule.WorkScheduler

NameTypeReadableWritableDescription
context10+WorkSchedulerExtensionContextYesNoContext of the WorkSchedulerExtensionAbility. This context inherits from ExtensionContext.

onWorkStart

onWorkStart(work: workScheduler.WorkInfo): void

Called when the system starts scheduling the deferred task.

System capability: SystemCapability.ResourceSchedule.WorkScheduler

Parameters

NameTypeMandatoryDescription
workworkScheduler.WorkInfoYesDeferred task that starts.

Example

import { workScheduler } from '@kit.BackgroundTasksKit';

export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
  onWorkStart(workInfo: workScheduler.WorkInfo) {
      console.log('MyWorkSchedulerExtensionAbility onWorkStart' + JSON.stringify(workInfo));
  }
}

onWorkStop

onWorkStop(work: workScheduler.WorkInfo): void

Called when the system stops scheduling the deferred task.

System capability: SystemCapability.ResourceSchedule.WorkScheduler

Parameters

NameTypeMandatoryDescription
workworkScheduler.WorkInfoYesDeferred task that stops.

Example

import { workScheduler } from '@kit.BackgroundTasksKit';

export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
  onWorkStop(workInfo: workScheduler.WorkInfo) {
      console.log('MyWorkSchedulerExtensionAbility onWorkStop' + JSON.stringify(workInfo));
  }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Background Tasks Kit

harmony 鸿蒙BackgroundProcessManager

harmony 鸿蒙TransientTask

harmony 鸿蒙TransientTask_DelaySuspendInfo

harmony 鸿蒙background_process_manager.h

harmony 鸿蒙DeviceUsageStatistics Error Codes

harmony 鸿蒙backgroundTaskManager Error Codes

harmony 鸿蒙reminderAgentManager Error Codes

harmony 鸿蒙workScheduler Error Codes

harmony 鸿蒙@ohos.resourceschedule.backgroundProcessManager (Background Child Process Management)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/aebVNo