未验证 提交 eb538028 编写于 作者: O openharmony_ci 提交者: Gitee

!9541 翻译完成:9302 后台任务管理doc修改

Merge pull request !9541 from wusongqing/TR9302
...@@ -265,7 +265,7 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -265,7 +265,7 @@ import featureAbility from '@ohos.ability.featureAbility';
import wantAgent from '@ohos.wantAgent'; import wantAgent from '@ohos.wantAgent';
import rpc from "@ohos.rpc"; import rpc from "@ohos.rpc";
function startBackgroundRunning() { function startContinuousTask() {
let wantAgentInfo = { let wantAgentInfo = {
// List of operations to be executed after the notification is clicked. // List of operations to be executed after the notification is clicked.
wants: [ wants: [
...@@ -293,7 +293,7 @@ function startBackgroundRunning() { ...@@ -293,7 +293,7 @@ function startBackgroundRunning() {
}); });
} }
function stopBackgroundRunning() { function stopContinuousTask() {
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
console.info("Operation stopBackgroundRunning succeeded"); console.info("Operation stopBackgroundRunning succeeded");
}).catch((err) => { }).catch((err) => {
...@@ -301,6 +301,13 @@ function stopBackgroundRunning() { ...@@ -301,6 +301,13 @@ function stopBackgroundRunning() {
}); });
} }
async function processAsyncJobs() {
// Execute the continuous task.
// After the continuous task is complete, call the API to release resources.
stopContinuousTask();
}
let mMyStub; let mMyStub;
class MyStub extends rpc.RemoteObject { class MyStub extends rpc.RemoteObject {
...@@ -315,11 +322,11 @@ class MyStub extends rpc.RemoteObject { ...@@ -315,11 +322,11 @@ class MyStub extends rpc.RemoteObject {
console.log('ServiceAbility onRemoteRequest called'); console.log('ServiceAbility onRemoteRequest called');
// The meaning of code is user-defined. // The meaning of code is user-defined.
if (code === 1) { if (code === 1) {
// Received the request code for requesting a continuous task. // Receive the request code for requesting a continuous task.
startContinuousTask(); startContinuousTask();
// Execute the continuous task. // Execute the continuous task.
} else if (code === 2) { } else if (code === 2) {
// Received the request code for canceling the continuous task. // Receive the request code for canceling the continuous task.
stopContinuousTask(); stopContinuousTask();
} else { } else {
console.log('ServiceAbility unknown request code'); console.log('ServiceAbility unknown request code');
...@@ -332,9 +339,9 @@ export default { ...@@ -332,9 +339,9 @@ export default {
onStart(want) { onStart(want) {
console.info('ServiceAbility onStart'); console.info('ServiceAbility onStart');
mMyStub = new MyStub("ServiceAbility-test"); mMyStub = new MyStub("ServiceAbility-test");
startBackgroundRunning(); // Call the API to start the task.
// Execute a specific continuous task in the background. startContinuousTask();
stopBackgroundRunning(); processAsyncJobs();
}, },
onStop() { onStop() {
console.info('ServiceAbility onStop'); console.info('ServiceAbility onStop');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册