Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c42aa374
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c42aa374
编写于
1月 31, 2023
作者:
G
Gloria
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update docs against 13792
Signed-off-by: wusongqing<wusongqing@huawei.com>
上级
8bc22295
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
53 addition
and
41 deletion
+53
-41
en/application-dev/task-management/continuous-task-dev-guide.md
...lication-dev/task-management/continuous-task-dev-guide.md
+53
-41
未找到文件。
en/application-dev/task-management/continuous-task-dev-guide.md
浏览文件 @
c42aa374
...
...
@@ -89,18 +89,22 @@ struct Index {
};
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
try
{
backgroundTaskManager
.
startBackgroundRunning
(
this
.
context
,
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation startBackgroundRunning succeeded
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation startBackgroundRunning failed Cause:
"
+
err
);
});
}
catch
(
error
)
{
console
.
error
(
`Operation startBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
});
try
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
try
{
backgroundTaskManager
.
startBackgroundRunning
(
this
.
context
,
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation startBackgroundRunning succeeded
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation startBackgroundRunning failed Cause:
"
+
err
);
});
}
catch
(
error
)
{
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
()
{
...
...
@@ -151,7 +155,7 @@ struct Index {
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
wantAgent
from
'
@ohos.app.ability.wantAgent
'
;
const
MSG_SEND_METHOD
:
string
=
'
CallSendMsg
'
;
...
...
@@ -176,25 +180,29 @@ function startContinuousTask() {
};
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
try
{
backgroundTaskManager
.
startBackgroundRunning
(
featureAbility
.
getContext
(),
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation startBackgroundRunning succeeded
"
);
}).
catch
((
error
)
=>
{
try
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
try
{
backgroundTaskManager
.
startBackgroundRunning
(
mContext
,
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation startBackgroundRunning succeeded
"
);
}).
catch
((
error
)
=>
{
console
.
error
(
`Operation startBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`Operation startBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
);
}
catch
(
error
)
{
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
((
err
or
)
=>
{
console
.
error
(
`Operation stopBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -312,7 +320,7 @@ If an application needs to interact with a continuous task in the background (fo
2.
Call the APIs for requesting and canceling a continuous task in the Service ability.
```
js
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
import
wantAgent
from
'
@ohos.app.ability.wantAgent
'
;
import
rpc
from
"
@ohos.rpc
"
;
...
...
@@ -335,18 +343,22 @@ function startContinuousTask() {
};
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
try
{
backgroundTaskManager
.
startBackgroundRunning
(
featureAbility
.
getContext
(),
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation startBackgroundRunning succeeded
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation startBackgroundRunning failed Cause:
"
+
err
);
});
}
catch
(
error
)
{
console
.
error
(
`Operation startBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
});
try
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
try
{
backgroundTaskManager
.
startBackgroundRunning
(
featureAbility
.
getContext
(),
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation startBackgroundRunning succeeded
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation startBackgroundRunning failed Cause:
"
+
err
);
});
}
catch
(
error
)
{
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录