diff --git a/zh-cn/application-dev/background-task-management/background-task-dev-guide.md b/zh-cn/application-dev/background-task-management/background-task-dev-guide.md index 92e3d3c99b700a391ab38e8fbe9d40d6388198ee..5a63a14acdb3b61bb765370cace0d7e5847aa322 100644 --- a/zh-cn/application-dev/background-task-management/background-task-dev-guide.md +++ b/zh-cn/application-dev/background-task-management/background-task-dev-guide.md @@ -42,7 +42,8 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager'; console.info("Request suspension delay will time out."); }); - var id = delayInfo.requestId;console.info("requestId is: " + id); + var id = delayInfo.requestId; + console.info("requestId is: " + id); ``` @@ -50,9 +51,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager'; ```js backgroundTaskManager.getRemainingDelayTime(id).then( res => { - console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); + console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); }).catch( err => { - console.log('promise => Operation failed. Cause: ' + err.data); + console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data); }); ``` @@ -83,9 +84,9 @@ console.info("The actualDelayTime is: " + time); // 获取应用程序进入挂起状态前的剩余时间 backgroundTaskManager.getRemainingDelayTime(id).then( res => { - console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); + console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); }).catch( err => { - console.log('promise => Operation failed. Cause: ' + err.data); + console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data); }); // 取消延迟挂起 @@ -172,16 +173,16 @@ ohos.permission.KEEP_BACKGROUND_RUNNING ], operationType: wantAgent.OperationType.START_ABILITY, requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] + wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; // 通过wantAgent模块的getWantAgent方法获取WantAgent对象 wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { - console.info("Operation succeeded"); + console.info("Operation startBackgroundRunning succeeded"); }).catch((err) => { - console.error("Operation failed Cause: " + err); + console.error("Operation startBackgroundRunning failed Cause: " + err); }); }); ``` @@ -193,9 +194,9 @@ ohos.permission.KEEP_BACKGROUND_RUNNING import featureAbility from '@ohos.ability.featureAbility'; backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { - console.info("Operation succeeded"); + console.info("Operation stopBackgroundRunning succeeded"); }).catch((err) => { - console.error("Operation failed Cause: " + err); + console.error("Operation stopBackgroundRunning failed Cause: " + err); }); ``` @@ -220,25 +221,25 @@ function startBackgroundRunning() { ], operationType: wantAgent.OperationType.START_ABILITY, requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] + wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; // 通过wantAgent模块的getWantAgent方法获取WantAgent对象 wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { - console.info("Operation succeeded"); + console.info("Operation startBackgroundRunning succeeded"); }).catch((err) => { - console.error("Operation failed Cause: " + err); + console.error("Operation startBackgroundRunning failed Cause: " + err); }); }); } function stopBackgroundRunning() { backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { - console.info("Operation succeeded"); + console.info("Operation stopBackgroundRunning succeeded"); }).catch((err) => { - console.error("Operation failed Cause: " + err); + console.error("Operation stopBackgroundRunning failed Cause: " + err); }); } diff --git a/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md b/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md index 5904644165e09533475ac6a2460f8b34e552df5c..3f8d0e482e570296e4a5503792b34e42721c5043 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md @@ -33,11 +33,17 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen | [DelaySuspendInfo](#delaysuspendinfo) | 返回延迟挂起信息。 | **示例**: + ```js let myReason = 'test requestSuspendDelay'; let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => { console.info("Request suspension delay will time out."); }) + + var id = delayInfo.requestId; + var time = delayInfo.actualDelayTime; + console.info("The requestId is: " + id); + console.info("The actualDelayTime is: " + time); ``` @@ -61,9 +67,9 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): let id = 1; backgroundTaskManager.getRemainingDelayTime(id, (err, res) => { if(err.data === 0) { - console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); + console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); } else { - console.log('promise => Operation failed. Cause: ' + err.data); + console.log('callback => Operation getRemainingDelayTime failed. Cause: ' + err.data); } }) ``` @@ -91,9 +97,9 @@ getRemainingDelayTime(requestId: number): Promise<number> ```js let id = 1; backgroundTaskManager.getRemainingDelayTime(id).then( res => { - console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); + console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); }).catch( err => { - console.log('promise => Operation failed. Cause: ' + err.data); + console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data); }) ``` @@ -143,9 +149,9 @@ import wantAgent from '@ohos.wantAgent'; function callback(err, data) { if (err) { - console.error("Operation failed Cause: " + err); + console.error("Operation startBackgroundRunning failed Cause: " + err); } else { - console.info("Operation succeeded"); + console.info("Operation startBackgroundRunning succeeded"); } } @@ -158,7 +164,7 @@ let wantAgentInfo = { ], operationType: wantAgent.OperationType.START_ABILITY, requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] + wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { @@ -206,15 +212,15 @@ let wantAgentInfo = { ], operationType: wantAgent.OperationType.START_ABILITY, requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] + wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { - console.info("Operation succeeded"); + console.info("Operation startBackgroundRunning succeeded"); }).catch((err) => { - console.error("Operation failed Cause: " + err); + console.error("Operation startBackgroundRunning failed Cause: " + err); }); }); @@ -241,9 +247,9 @@ import featureAbility from '@ohos.ability.featureAbility'; function callback(err, data) { if (err) { - console.error("Operation failed Cause: " + err); + console.error("Operation stopBackgroundRunning failed Cause: " + err); } else { - console.info("Operation succeeded"); + console.info("Operation stopBackgroundRunning succeeded"); } } @@ -275,9 +281,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager'; import featureAbility from '@ohos.ability.featureAbility'; backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { - console.info("Operation succeeded"); + console.info("Operation stopBackgroundRunning succeeded"); }).catch((err) => { - console.error("Operation failed Cause: " + err); + console.error("Operation stopBackgroundRunning failed Cause: " + err); }); ```