• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.WorkSchedulerExtensionAbility (Work Scheduler Callbacks)
2
3The **WorkSchedulerExtensionAbility** module provides callbacks for Work Scheduler tasks.
4
5When developing an application, you can override the APIs of this module and add your own task logic to the APIs.
6
7>  **NOTE**
8>
9>  - 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.
10>  - The APIs of this module can be used only in the stage model.
11
12
13## Modules to Import
14
15```ts
16import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'
17```
18
19## WorkSchedulerExtensionAbility.onWorkStart
20
21onWorkStart(work: workScheduler.WorkInfo): void
22
23Triggered when the Work Scheduler task starts.
24
25**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
26
27**Parameters**
28
29| Name | Type                                      | Mandatory  | Description            |
30| ---- | ---------------------------------------- | ---- | -------------- |
31| work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes   | Target task.|
32
33**Example**
34
35  ```ts
36    export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
37        onWorkStart(workInfo) {
38            console.log('MyWorkSchedulerExtensionAbility onWorkStart' + JSON.stringify(workInfo));
39        }
40    }
41  ```
42
43## WorkSchedulerExtensionAbility.onWorkStop
44
45onWorkStop(work: workScheduler.WorkInfo): void
46
47Triggered when the Work Scheduler task stops.
48
49**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
50
51**Parameters**
52
53| Name | Type                                      | Mandatory  | Description            |
54| ---- | ---------------------------------------- | ---- | -------------- |
55| work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes   | Target task.|
56
57
58**Example**
59
60  ```ts
61    export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
62        onWorkStop(workInfo) {
63            console.log('MyWorkSchedulerExtensionAbility onWorkStop' + JSON.stringify(workInfo));
64        }
65    }
66  ```
67