js-apis-WorkSchedulerExtensionAbility.md 1.8 KB
Newer Older
E
esterzhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Work Scheduler Callbacks

> ![icon-note.gif](public_sys-resources/icon-note.gif) **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.


## Modules to Import

```
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'
```

## WorkSchedulerExtensionAbility.onWorkStart

E
ester.zhou 已提交
15
onWorkStart(work: workScheduler.WorkInfo): void
E
esterzhou 已提交
16 17 18

Triggered when the Work Scheduler task starts.

E
ester.zhou 已提交
19 20 21 22 23 24 25 26 27
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler

**Parameters**

| Name | Type                   | Mandatory  | Description            |
| ---- | --------------------- | ---- | -------------- |
| work | [workScheduler.WorkInfo](js-apis-workScheduler.md#workinfo) | Yes   | Task to be added to the execution queue.|

**Example**
E
esterzhou 已提交
28 29 30 31 32 33 34 35 36 37 38

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

## WorkSchedulerExtensionAbility.onWorkStop

E
ester.zhou 已提交
39
onWorkStop(work: workScheduler.WorkInfo)
E
esterzhou 已提交
40 41 42

Triggered when the Work Scheduler task stops.

E
ester.zhou 已提交
43 44 45 46 47 48 49 50 51 52
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler

**Parameters**

| Name | Type                   | Mandatory  | Description            |
| ---- | --------------------- | ---- | -------------- |
| work | [workScheduler.WorkInfo](js-apis-workScheduler.md#workinfo) | Yes   | Task to be added to the execution queue.|


**Example**
E
esterzhou 已提交
53 54 55 56 57 58 59 60

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