提交 fa179739 编写于 作者: Z zhangxin_T

bgtask doc bugfix

Signed-off-by: Nzhangxin_T <zhangxin312@huawei.com>
上级 ba4ccd23
......@@ -57,7 +57,7 @@ OpenHarmony提供了九种后台模式,供需要在后台做长时任务的业
| audioRecording | 音频输入 | 正在运行录音任务 | - |
| location | 定位、导航 | 正在运行定位任务 | - |
| bluetoothInteraction | 蓝牙传输 | 正在运行蓝牙相关任务 | - |
| multiDeviceConnection | 分布式互联任务 | 正在运行分布式任务 | - |
| multiDeviceConnection | 应用跨设备多端协同 | 正在运行分布式任务 | - |
| wifiInteraction | WLAN传输 | 正在运行WLAN相关任务 | System API,仅对System权限应用开放 |
| voip | 音视频电话、VOIP | 正在运行通话相关任务 | System API,仅对System权限应用开放 |
| taskKeeping | 计算任务 | 正在运行计算任务 | 仅在特定设备生效 |
......
......@@ -42,7 +42,7 @@
当需要与后台执行的长时任务交互时(如播放音乐等)。可以采用connectAbility()方法启动并连接Service Ability。在获取到服务的代理对象后,与服务进行通信,控制长时任务的申请和取消。
1、新建Api Version 8的工程后,在工程目录中右键选择“new” -> “Ability” -> “Service Ability” 快速创建Service Ability组件。并在config.json文件中配置长时任务权限ohos.permission.KEEP_BACKGROUND_RUNNING、后台模式类型,其中Ability类型为“service”
1、在config.json文件中配置长时任务权限ohos.permission.KEEP_BACKGROUND_RUNNING、同时为需要使用长时任务的Service Ability声明相应的后台模式类型
```
"module": {
......@@ -181,7 +181,7 @@ export default {
Stage模型的相关信息参考[Stage开发概述](../application-models/stage-model-development-overview.md)
1、新建Api Version 9的工程后,在工程目录中右键选择“New” -> “Ability” 快速创建Ability组件。并在module.json5文件中配置长时任务权限ohos.permission.KEEP_BACKGROUND_RUNNING、后台模式类型。
1、在module.json5文件中配置长时任务权限ohos.permission.KEEP_BACKGROUND_RUNNING、同时为需要使用长时任务的ability声明相应的后台模式类型。
```
"module": {
......@@ -321,7 +321,7 @@ function startContinuousTask() {
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象
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) => {
......@@ -335,9 +335,9 @@ function startContinuousTask() {
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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册