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

!9302 后台任务管理doc修改

Merge pull request !9302 from 张鑫/master
...@@ -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 = {
// 点击通知后,将要执行的动作列表 // 点击通知后,将要执行的动作列表
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() {
// 此处执行具体的长时任务。
// 长时任务执行完,调用取消接口,释放资源。
stopContinuousTask();
}
let mMyStub; let mMyStub;
class MyStub extends rpc.RemoteObject { class MyStub extends rpc.RemoteObject {
...@@ -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(); // 在执行后台长时任前,调用申请接口。
// 此处执行后台具体的长时任务。 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.
先完成此消息的编辑!
想要评论请 注册