Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8976b097
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8976b097
编写于
4月 18, 2022
作者:
W
wangqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
描述修改
Signed-off-by:
N
wangqing
<
wangqing136@huawei.com
>
上级
6441fa65
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
29 deletion
+36
-29
zh-cn/application-dev/background-task-management/background-task-dev-guide.md
...v/background-task-management/background-task-dev-guide.md
+16
-15
zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md
...ation-dev/reference/apis/js-apis-backgroundTaskManager.md
+20
-14
未找到文件。
zh-cn/application-dev/background-task-management/background-task-dev-guide.md
浏览文件 @
8976b097
...
@@ -42,7 +42,8 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
...
@@ -42,7 +42,8 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
console.info("Request suspension delay will time out.");
console.info("Request suspension delay will time out.");
});
});
var id = delayInfo.requestId;console.info("requestId is: " + id);
var id = delayInfo.requestId;
console.info("requestId is: " + id);
```
```
...
@@ -50,9 +51,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
...
@@ -50,9 +51,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
```js
```js
backgroundTaskManager.getRemainingDelayTime(id).then( res => {
backgroundTaskManager.getRemainingDelayTime(id).then( res => {
console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res));
console.log('promise => Operation
getRemainingDelayTime
succeeded. Data: ' + JSON.stringify(res));
}).catch( err => {
}).catch( err => {
console.log('promise => Operation failed. Cause: ' + err.data);
console.log('promise => Operation
getRemainingDelayTime
failed. Cause: ' + err.data);
});
});
```
```
...
@@ -83,9 +84,9 @@ console.info("The actualDelayTime is: " + time);
...
@@ -83,9 +84,9 @@ console.info("The actualDelayTime is: " + time);
// 获取应用程序进入挂起状态前的剩余时间
// 获取应用程序进入挂起状态前的剩余时间
backgroundTaskManager
.
getRemainingDelayTime
(
id
).
then
(
res
=>
{
backgroundTaskManager
.
getRemainingDelayTime
(
id
).
then
(
res
=>
{
console
.
log
(
'
promise => Operation succeeded. Data:
'
+
JSON
.
stringify
(
res
));
console
.
log
(
'
promise => Operation
getRemainingDelayTime
succeeded. Data:
'
+
JSON
.
stringify
(
res
));
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
log
(
'
promise => Operation failed. Cause:
'
+
err
.
data
);
console
.
log
(
'
promise => Operation
getRemainingDelayTime
failed. Cause:
'
+
err
.
data
);
});
});
// 取消延迟挂起
// 取消延迟挂起
...
@@ -172,16 +173,16 @@ ohos.permission.KEEP_BACKGROUND_RUNNING
...
@@ -172,16 +173,16 @@ ohos.permission.KEEP_BACKGROUND_RUNNING
],
],
operationType: wantAgent.OperationType.START_ABILITY,
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG]
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESE
N
T_FLAG]
};
};
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
console.info("Operation succeeded");
console.info("Operation s
tartBackgroundRunning s
ucceeded");
}).catch((err) => {
}).catch((err) => {
console.error("Operation failed Cause: " + err);
console.error("Operation
startBackgroundRunning
failed Cause: " + err);
});
});
});
});
```
```
...
@@ -193,9 +194,9 @@ ohos.permission.KEEP_BACKGROUND_RUNNING
...
@@ -193,9 +194,9 @@ ohos.permission.KEEP_BACKGROUND_RUNNING
import featureAbility from '@ohos.ability.featureAbility';
import featureAbility from '@ohos.ability.featureAbility';
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
console.info("Operation succeeded");
console.info("Operation s
topBackgroundRunning s
ucceeded");
}).catch((err) => {
}).catch((err) => {
console.error("Operation failed Cause: " + err);
console.error("Operation
stopBackgroundRunning
failed Cause: " + err);
});
});
```
```
...
@@ -220,25 +221,25 @@ function startBackgroundRunning() {
...
@@ -220,25 +221,25 @@ function startBackgroundRunning() {
],
],
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
requestCode
:
0
,
requestCode
:
0
,
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
UPDATE_PRESET_FLAG
]
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
UPDATE_PRESE
N
T_FLAG
]
};
};
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
backgroundTaskManager
.
startBackgroundRunning
(
featureAbility
.
getContext
(),
backgroundTaskManager
.
startBackgroundRunning
(
featureAbility
.
getContext
(),
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation succeeded
"
);
console
.
info
(
"
Operation s
tartBackgroundRunning s
ucceeded
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation failed Cause:
"
+
err
);
console
.
error
(
"
Operation
startBackgroundRunning
failed Cause:
"
+
err
);
});
});
});
});
}
}
function
stopBackgroundRunning
()
{
function
stopBackgroundRunning
()
{
backgroundTaskManager
.
stopBackgroundRunning
(
featureAbility
.
getContext
()).
then
(()
=>
{
backgroundTaskManager
.
stopBackgroundRunning
(
featureAbility
.
getContext
()).
then
(()
=>
{
console
.
info
(
"
Operation succeeded
"
);
console
.
info
(
"
Operation s
topBackgroundRunning s
ucceeded
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation failed Cause:
"
+
err
);
console
.
error
(
"
Operation
stopBackgroundRunning
failed Cause:
"
+
err
);
});
});
}
}
...
...
zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md
浏览文件 @
8976b097
...
@@ -33,11 +33,17 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen
...
@@ -33,11 +33,17 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen
|
[
DelaySuspendInfo
](
#delaysuspendinfo
)
| 返回延迟挂起信息。 |
|
[
DelaySuspendInfo
](
#delaysuspendinfo
)
| 返回延迟挂起信息。 |
**示例**
:
**示例**
:
```
js
```
js
let
myReason
=
'
test requestSuspendDelay
'
;
let
myReason
=
'
test requestSuspendDelay
'
;
let
delayInfo
=
backgroundTaskManager
.
requestSuspendDelay
(
myReason
,
()
=>
{
let
delayInfo
=
backgroundTaskManager
.
requestSuspendDelay
(
myReason
,
()
=>
{
console
.
info
(
"
Request suspension delay will time out.
"
);
console
.
info
(
"
Request suspension delay will time out.
"
);
})
})
var
id
=
delayInfo
.
requestId
;
var
time
=
delayInfo
.
actualDelayTime
;
console
.
info
(
"
The requestId is:
"
+
id
);
console
.
info
(
"
The actualDelayTime is:
"
+
time
);
```
```
...
@@ -61,9 +67,9 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>):
...
@@ -61,9 +67,9 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>):
let
id
=
1
;
let
id
=
1
;
backgroundTaskManager
.
getRemainingDelayTime
(
id
,
(
err
,
res
)
=>
{
backgroundTaskManager
.
getRemainingDelayTime
(
id
,
(
err
,
res
)
=>
{
if
(
err
.
data
===
0
)
{
if
(
err
.
data
===
0
)
{
console
.
log
(
'
promise => Operation
succeeded. Data:
'
+
JSON
.
stringify
(
res
));
console
.
log
(
'
callback => Operation getRemainingDelayTime
succeeded. Data:
'
+
JSON
.
stringify
(
res
));
}
else
{
}
else
{
console
.
log
(
'
promise => Operation
failed. Cause:
'
+
err
.
data
);
console
.
log
(
'
callback => Operation getRemainingDelayTime
failed. Cause:
'
+
err
.
data
);
}
}
})
})
```
```
...
@@ -91,9 +97,9 @@ getRemainingDelayTime(requestId: number): Promise<number>
...
@@ -91,9 +97,9 @@ getRemainingDelayTime(requestId: number): Promise<number>
```
js
```
js
let
id
=
1
;
let
id
=
1
;
backgroundTaskManager
.
getRemainingDelayTime
(
id
).
then
(
res
=>
{
backgroundTaskManager
.
getRemainingDelayTime
(
id
).
then
(
res
=>
{
console
.
log
(
'
promise => Operation succeeded. Data:
'
+
JSON
.
stringify
(
res
));
console
.
log
(
'
promise => Operation
getRemainingDelayTime
succeeded. Data:
'
+
JSON
.
stringify
(
res
));
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
log
(
'
promise => Operation failed. Cause:
'
+
err
.
data
);
console
.
log
(
'
promise => Operation
getRemainingDelayTime
failed. Cause:
'
+
err
.
data
);
})
})
```
```
...
@@ -143,9 +149,9 @@ import wantAgent from '@ohos.wantAgent';
...
@@ -143,9 +149,9 @@ import wantAgent from '@ohos.wantAgent';
function
callback
(
err
,
data
)
{
function
callback
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
"
Operation failed Cause:
"
+
err
);
console
.
error
(
"
Operation
startBackgroundRunning
failed Cause:
"
+
err
);
}
else
{
}
else
{
console
.
info
(
"
Operation succeeded
"
);
console
.
info
(
"
Operation s
tartBackgroundRunning s
ucceeded
"
);
}
}
}
}
...
@@ -158,7 +164,7 @@ let wantAgentInfo = {
...
@@ -158,7 +164,7 @@ let wantAgentInfo = {
],
],
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
requestCode
:
0
,
requestCode
:
0
,
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
UPDATE_PRESET_FLAG
]
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
UPDATE_PRESE
N
T_FLAG
]
};
};
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
...
@@ -206,15 +212,15 @@ let wantAgentInfo = {
...
@@ -206,15 +212,15 @@ let wantAgentInfo = {
],
],
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
requestCode
:
0
,
requestCode
:
0
,
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
UPDATE_PRESET_FLAG
]
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
UPDATE_PRESE
N
T_FLAG
]
};
};
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
backgroundTaskManager
.
startBackgroundRunning
(
featureAbility
.
getContext
(),
backgroundTaskManager
.
startBackgroundRunning
(
featureAbility
.
getContext
(),
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation succeeded
"
);
console
.
info
(
"
Operation s
tartBackgroundRunning s
ucceeded
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation failed Cause:
"
+
err
);
console
.
error
(
"
Operation
startBackgroundRunning
failed Cause:
"
+
err
);
});
});
});
});
...
@@ -241,9 +247,9 @@ import featureAbility from '@ohos.ability.featureAbility';
...
@@ -241,9 +247,9 @@ import featureAbility from '@ohos.ability.featureAbility';
function
callback
(
err
,
data
)
{
function
callback
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
"
Operation failed Cause:
"
+
err
);
console
.
error
(
"
Operation
stopBackgroundRunning
failed Cause:
"
+
err
);
}
else
{
}
else
{
console
.
info
(
"
Operation succeeded
"
);
console
.
info
(
"
Operation s
topBackgroundRunning s
ucceeded
"
);
}
}
}
}
...
@@ -275,9 +281,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
...
@@ -275,9 +281,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
backgroundTaskManager
.
stopBackgroundRunning
(
featureAbility
.
getContext
()).
then
(()
=>
{
backgroundTaskManager
.
stopBackgroundRunning
(
featureAbility
.
getContext
()).
then
(()
=>
{
console
.
info
(
"
Operation succeeded
"
);
console
.
info
(
"
Operation s
topBackgroundRunning s
ucceeded
"
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation failed Cause:
"
+
err
);
console
.
error
(
"
Operation
stopBackgroundRunning
failed Cause:
"
+
err
);
});
});
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录