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

!14108 翻译完成:13792 长时任务开发者指南示例代码vod问题处理

Merge pull request !14108 from wusongqing/TR13792
......@@ -89,6 +89,7 @@ struct Index {
};
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
try {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
try {
backgroundTaskManager.startBackgroundRunning(this.context,
......@@ -101,6 +102,9 @@ struct Index {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
}
});
} catch (error) {
console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`);
}
}
stopContinuousTask() {
......@@ -176,9 +180,10 @@ function startContinuousTask() {
};
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
try {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
try {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.startBackgroundRunning(mContext,
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
console.info("Operation startBackgroundRunning succeeded");
}).catch((error) => {
......@@ -188,13 +193,16 @@ function startContinuousTask() {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
}
});
} catch (error) {
console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`);
}
}
function stopContinuousTask() {
try {
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
backgroundTaskManager.stopBackgroundRunning(mContext).then(() => {
console.info("Operation stopBackgroundRunning succeeded");
}).catch((err) => {
}).catch((error) => {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
});
} catch (error) {
......@@ -335,6 +343,7 @@ function startContinuousTask() {
};
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
try {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
try {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
......@@ -347,6 +356,9 @@ function startContinuousTask() {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
}
});
} catch (error) {
console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`);
}
}
function stopContinuousTask() {
......@@ -396,7 +408,7 @@ class MyStub extends rpc.RemoteObject {
}
export default {
onStart(want) {
onStart() {
console.info('ServiceAbility onStart');
mMyStub = new MyStub("ServiceAbility-test");
// Call the API to start the task.
......@@ -416,7 +428,7 @@ export default {
onDisconnect() {
console.info('ServiceAbility onDisconnect');
},
onCommand(want, restart, startId) {
onCommand(want, startId) {
console.info('ServiceAbility onCommand');
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册