harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (Deferred Task Scheduling Callbacks)

2022-08-09 浏览 (1181)

@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 '@ohos.WorkSchedulerExtensionAbility';

Attributes

System capability: SystemCapability.ResourceSchedule.WorkScheduler

NameTypeReadableWritableDescription
context10+WorkSchedulerExtensionContextYesNoContext of the WorkSchedulerExtension. This context is inherited from ExtensionContext.

WorkSchedulerExtensionAbility.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 '@ohos.resourceschedule.workScheduler';

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

WorkSchedulerExtensionAbility.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 '@ohos.resourceschedule.workScheduler';

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

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

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