From 90d7816579dacaac9c24aa2b8e3ee09c8f748ddd Mon Sep 17 00:00:00 2001 From: wusongqing Date: Mon, 6 Jun 2022 17:53:54 +0800 Subject: [PATCH] updated docs Signed-off-by: wusongqing --- .../background-task-dev-guide.md | 12 ++++-- .../apis/js-apis-backgroundTaskManager.md | 38 +++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/en/application-dev/background-task-management/background-task-dev-guide.md b/en/application-dev/background-task-management/background-task-dev-guide.md index f3ccfe0106..74874b3116 100644 --- a/en/application-dev/background-task-management/background-task-dev-guide.md +++ b/en/application-dev/background-task-management/background-task-dev-guide.md @@ -41,7 +41,7 @@ If a service needs to be continued when the application or service module is run backgroundTaskManager.getRemainingDelayTime(id).then( res => { console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); }).catch( err => { - console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data); + console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.code); }); ``` @@ -74,7 +74,7 @@ console.info("The actualDelayTime is: " + time); backgroundTaskManager.getRemainingDelayTime(id).then( res => { console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); }).catch( err => { - console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data); + console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.code); }); // Cancel the suspension delay. @@ -187,7 +187,7 @@ For details about how to use the Service ability in the FA model, see [Service A If an application does not need to interact with a continuous task in the background, you can use **startAbility()** to start the Service ability. In the **onStart** callback of the Service ability, call **startBackgroundRunning()** to declare that the Service ability needs to run in the background for a long time. After the task execution is complete, call **stopBackgroundRunning()** to release resources. -If an application needs to interact with a continuous task in the background (for example, an application related to music playback), you can use **connectAbility()** to start and connect to the Service ability. After obtaining the proxy of the Service ability, the application can communicate with the Service ability and control the application and cancellation of continuous tasks. +If an application needs to interact with a continuous task in the background (for example, an application related to music playback), you can use **connectAbility()** to start and connect to the Service ability. After obtaining the proxy of the Service ability, the application can communicate with the Service ability and control the request and cancellation of continuous tasks. ```js import backgroundTaskManager from '@ohos.backgroundTaskManager'; @@ -284,3 +284,9 @@ export default { } }; ``` + +## Samples + +The following sample is provided to help you better understand how to develop background task management: + +- [BackgroundTaskManager: Background Task Management (eTS, API version 8)](https://gitee.com/openharmony/app_samples/tree/master/ResourcesSchedule/BackgroundTaskManager) diff --git a/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md b/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md index db39b0dbad..68b16ef535 100644 --- a/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md +++ b/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md @@ -1,6 +1,6 @@ # Background Task Management -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> **NOTE** > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -25,7 +25,7 @@ The default duration of delayed suspension is 180000 when the battery level is h | Name | Type | Mandatory | Description | | -------- | -------------------- | ---- | ------------------------------ | | reason | string | Yes | Reason for delayed transition to the suspended state. | -| callback | Callback<void> | Yes | Invoked when a delay is about to time out. Generally, this callback is used to notify the application 6 seconds before the delay times out. | +| callback | Callback<void> | Yes | Invoked when a delay is about to time out. Generally, this callback is used to notify the application 6 seconds before the delay times out.| **Return value** | Type | Description | @@ -66,10 +66,10 @@ Obtains the remaining duration before the application is suspended. This API use ```js let id = 1; backgroundTaskManager.getRemainingDelayTime(id, (err, res) => { - if(err.data === 0) { - console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); + if(err) { + console.log('callback => Operation getRemainingDelayTime failed. Cause: ' + err.code); } else { - console.log('callback => Operation getRemainingDelayTime failed. Cause: ' + err.data); + console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); } }) ``` @@ -99,7 +99,7 @@ Obtains the remaining duration before the application is suspended. This API use backgroundTaskManager.getRemainingDelayTime(id).then( res => { console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); }).catch( err => { - console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data); + console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.code); }) ``` @@ -186,16 +186,16 @@ Requests a continuous task from the system. This API uses a promise to return th **Parameters** -| Name | Type | Mandatory | Description | +| Name | Type | Mandatory | Description | | --------- | ---------------------------------- | ---- | ----------------------- | -| context | [Context](js-apis-Context.md) | Yes | Application context. | -| bgMode | [BackgroundMode](#backgroundmode8) | Yes | Background mode requested. | -| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. | +| context | [Context](js-apis-Context.md) | Yes | Application context. | +| bgMode | [BackgroundMode](#backgroundmode8) | Yes | Background mode requested. | +| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked.| **Return value** -| Type | Description | +| Type | Description | | -------------- | ---------------- | -| Promise\ | Promise used to return the result. | +| Promise\ | Promise used to return the result.| **Example** ```js @@ -235,10 +235,10 @@ Requests to cancel a continuous task. This API uses an asynchronous callback to **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **Parameters** -| Name | Type | Mandatory | Description | +| Name | Type | Mandatory | Description | | -------- | ----------------------------- | ---- | ---------------------- | -| context | [Context](js-apis-Context.md) | Yes | Application context. | -| callback | AsyncCallback<void> | Yes | Callback used to return the result. | +| context | [Context](js-apis-Context.md) | Yes | Application context. | +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js @@ -266,14 +266,14 @@ Requests to cancel a continuous task. This API uses a promise to return the resu **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **Parameters** -| Name | Type | Mandatory | Description | +| Name | Type | Mandatory | Description | | ------- | ----------------------------- | ---- | --------- | -| context | [Context](js-apis-Context.md) | Yes | Application context. | +| context | [Context](js-apis-Context.md) | Yes | Application context.| **Return value** -| Type | Description | +| Type | Description | | -------------- | ---------------- | -| Promise\ | Promise used to return the result. | +| Promise\ | Promise used to return the result.| **Example** ```js -- GitLab