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