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

!9312 后台任务管理doc修改

Merge pull request !9312 from 张鑫/OpenHarmony-3.1-Release
...@@ -195,7 +195,7 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -195,7 +195,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 = {
// 点击通知后,将要执行的动作列表 // 点击通知后,将要执行的动作列表
wants: [ wants: [
...@@ -223,7 +223,7 @@ function startBackgroundRunning() { ...@@ -223,7 +223,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) => {
...@@ -231,6 +231,13 @@ function stopBackgroundRunning() { ...@@ -231,6 +231,13 @@ function stopBackgroundRunning() {
}); });
} }
async function processAsyncJobs() {
// 此处执行具体的长时任务。
// 长时任务执行完,调用取消接口,释放资源。
stopContinuousTask();
}
let mMyStub; let mMyStub;
class MyStub extends rpc.RemoteObject { class MyStub extends rpc.RemoteObject {
...@@ -262,9 +269,9 @@ export default { ...@@ -262,9 +269,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(); // 在执行后台长时任前,调用申请接口。
// 此处执行后台具体的长时任务。 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.
先完成此消息的编辑!
想要评论请 注册