Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
f43fca76
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看板
未验证
提交
f43fca76
编写于
9月 04, 2023
作者:
朱
朱天怡
提交者:
Gitee
9月 04, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
告警修复
Signed-off-by:
N
朱天怡
<
zhutianyi2@huawei.com
>
上级
5be5552b
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
133 addition
and
160 deletion
+133
-160
zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md
...ation-dev/reference/apis/js-apis-backgroundTaskManager.md
+8
-8
zh-cn/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md
...ce/apis/js-apis-resourceschedule-backgroundTaskManager.md
+67
-66
zh-cn/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md
.../reference/apis/js-apis-resourceschedule-workScheduler.md
+51
-79
zh-cn/application-dev/task-management/continuous-task.md
zh-cn/application-dev/task-management/continuous-task.md
+2
-2
zh-cn/application-dev/task-management/work-scheduler.md
zh-cn/application-dev/task-management/work-scheduler.md
+5
-5
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md
浏览文件 @
f43fca76
...
...
@@ -17,7 +17,7 @@
## 导入模块
```
j
s
```
t
s
import
backgroundTaskManager
from
'
@ohos.backgroundTaskManager
'
;
```
...
...
@@ -47,7 +47,7 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen
**示例**
:
```
j
s
```
t
s
import
backgroundTaskManager
from
'
@ohos.backgroundTaskManager
'
;
let
myReason
=
'
test requestSuspendDelay
'
;
...
...
@@ -79,11 +79,11 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>):
**示例**
:
```
j
s
```
t
s
import
backgroundTaskManager
from
'
@ohos.backgroundTaskManager
'
;
let
delayInfo
=
backgroundTaskManager
.
requestSuspendDelay
(
"
test
"
,
()
=>
{});
backgroundTaskManager
.
getRemainingDelayTime
(
delayInfo
.
requestId
,
(
err
,
res
)
=>
{
backgroundTaskManager
.
getRemainingDelayTime
(
delayInfo
.
requestId
,
(
err
:
BusinessError
,
res
:
number
)
=>
{
if
(
err
)
{
console
.
log
(
'
callback => Operation getRemainingDelayTime failed. Cause:
'
+
err
.
code
);
}
else
{
...
...
@@ -115,7 +115,7 @@ getRemainingDelayTime(requestId: number): Promise<number>
**示例**
:
```
j
s
```
t
s
let
delayInfo
=
backgroundTaskManager
.
requestSuspendDelay
(
"
test
"
,
()
=>
{});
backgroundTaskManager
.
getRemainingDelayTime
(
delayInfo
.
requestId
).
then
((
res
:
number
)
=>
{
console
.
log
(
'
promise => Operation getRemainingDelayTime succeeded. Data:
'
+
JSON
.
stringify
(
res
));
...
...
@@ -141,7 +141,7 @@ cancelSuspendDelay(requestId: number): void
**示例**
:
```
j
s
```
t
s
let
delayInfo
=
backgroundTaskManager
.
requestSuspendDelay
(
"
test
"
,
()
=>
{});
backgroundTaskManager
.
cancelSuspendDelay
(
delayInfo
.
requestId
);
```
...
...
@@ -267,7 +267,7 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
**示例**
:
FA模型示例:
FA模型示例
(需使用js代码开发)
:
```
js
import
backgroundTaskManager
from
'
@ohos.backgroundTaskManager
'
;
...
...
@@ -348,7 +348,7 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): vo
**示例**
:
FA模型示例:
FA模型示例
(需使用js代码开发)
:
```
js
import
backgroundTaskManager
from
'
@ohos.backgroundTaskManager
'
;
...
...
zh-cn/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md
浏览文件 @
f43fca76
...
...
@@ -9,7 +9,7 @@
## 导入模块
```
j
s
```
t
s
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
```
...
...
@@ -53,22 +53,23 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen
**示例**
:
```
js
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
```
ts
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
myReason
=
'
test requestSuspendDelay
'
;
try
{
let
delayInfo
=
backgroundTaskManager
.
requestSuspendDelay
(
myReason
,
()
=>
{
let
myReason
=
'
test requestSuspendDelay
'
;
try
{
let
delayInfo
=
backgroundTaskManager
.
requestSuspendDelay
(
myReason
,
()
=>
{
console
.
info
(
"
Request suspension delay will time out.
"
);
})
let
id
=
delayInfo
.
requestId
;
let
time
=
delayInfo
.
actualDelayTime
;
console
.
info
(
"
The requestId is:
"
+
id
);
console
.
info
(
"
The actualDelayTime is:
"
+
time
);
}
catch
(
error
)
{
console
.
error
(
`requestSuspendDelay failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
})
let
id
=
delayInfo
.
requestId
;
let
time
=
delayInfo
.
actualDelayTime
;
console
.
info
(
"
The requestId is:
"
+
id
);
console
.
info
(
"
The actualDelayTime is:
"
+
time
);
}
catch
(
error
)
{
console
.
error
(
`requestSuspendDelay failed. code is
${(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
```
## backgroundTaskManager.getRemainingDelayTime
...
...
@@ -102,22 +103,19 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>):
**示例**
:
```
js
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
```
ts
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
id
=
1
;
try
{
backgroundTaskManager
.
getRemainingDelayTime
(
id
,
(
error
,
res
)
=>
{
let
id
=
1
;
backgroundTaskManager
.
getRemainingDelayTime
(
id
,
(
error
:
BusinessError
,
res
:
number
)
=>
{
if
(
error
)
{
console
.
error
(
`callback => Operation getRemainingDelayTime failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
else
{
console
.
log
(
'
callback => Operation getRemainingDelayTime succeeded. Data:
'
+
JSON
.
stringify
(
res
));
}
})
}
catch
(
error
)
{
console
.
error
(
`callback => Operation getRemainingDelayTime failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
})
```
## backgroundTaskManager.getRemainingDelayTime
...
...
@@ -155,20 +153,17 @@ getRemainingDelayTime(requestId: number): Promise<number>
**示例**
:
```
js
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
```
ts
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
id
=
1
;
try
{
backgroundTaskManager
.
getRemainingDelayTime
(
id
).
then
(
res
=>
{
let
id
=
1
;
backgroundTaskManager
.
getRemainingDelayTime
(
id
).
then
((
res
:
number
)
=>
{
console
.
log
(
'
promise => Operation getRemainingDelayTime succeeded. Data:
'
+
JSON
.
stringify
(
res
));
}).
catch
(
error
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`promise => Operation getRemainingDelayTime failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
})
}
catch
(
error
)
{
console
.
error
(
`promise => Operation getRemainingDelayTime failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
})
```
## backgroundTaskManager.cancelSuspendDelay
...
...
@@ -202,12 +197,13 @@ cancelSuspendDelay(requestId: number): void
```
js
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
id
=
1
;
try
{
backgroundTaskManager
.
cancelSuspendDelay
(
id
);
}
catch
(
error
)
{
console
.
error
(
`cancelSuspendDelay failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`cancelSuspendDelay failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -249,9 +245,10 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
```
js
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
wantAgent
from
'
@ohos.app.ability.wantAgent
'
;
import
wantAgent
,
{
WantAgent
}
from
'
@ohos.app.ability.wantAgent
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
function
callback
(
error
,
data
)
{
function
callback
(
error
:
BusinessError
,
data
:
void
)
{
if
(
error
)
{
console
.
error
(
`Operation startBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
else
{
...
...
@@ -260,8 +257,8 @@ function callback(error, data) {
}
export
default
class
EntryAbility
extends
UIAbility
{
onCreate
(
want
,
l
aunchParam
)
{
let
wantAgentInfo
=
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
let
wantAgentInfo
:
wantAgent
.
WantAgentInfo
=
{
wants
:
[
{
bundleName
:
"
com.example.myapplication
"
,
...
...
@@ -274,16 +271,16 @@ export default class EntryAbility extends UIAbility {
};
try
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
:
WantAgent
)
=>
{
try
{
backgroundTaskManager
.
startBackgroundRunning
(
this
.
context
,
backgroundTaskManager
.
BackgroundMode
.
LOCATION
,
wantAgentObj
,
callback
)
}
catch
(
error
)
{
console
.
error
(
`Operation startBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`Operation startBackgroundRunning failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
});
}
catch
(
error
)
{
console
.
error
(
`Operation getWantAgent failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`Operation getWantAgent failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
}
};
...
...
@@ -332,11 +329,12 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
```
js
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
wantAgent
from
'
@ohos.app.ability.wantAgent
'
;
import
wantAgent
,
{
WantAgent
}
from
'
@ohos.app.ability.wantAgent
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
export
default
class
EntryAbility
extends
UIAbility
{
onCreate
(
want
,
l
aunchParam
)
{
let
wantAgentInfo
=
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
let
wantAgentInfo
:
wantAgent
.
WantAgentInfo
=
{
wants
:
[
{
bundleName
:
"
com.example.myapplication
"
,
...
...
@@ -349,20 +347,20 @@ export default class EntryAbility extends UIAbility {
};
try
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
)
=>
{
wantAgent
.
getWantAgent
(
wantAgentInfo
).
then
((
wantAgentObj
:
WantAgent
)
=>
{
try
{
backgroundTaskManager
.
startBackgroundRunning
(
this
.
context
,
backgroundTaskManager
.
BackgroundMode
.
LOCATION
,
wantAgentObj
).
then
(()
=>
{
console
.
info
(
"
Operation startBackgroundRunning succeeded
"
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
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
}
`
);
console
.
error
(
`Operation startBackgroundRunning failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
});
}
catch
(
error
)
{
console
.
error
(
`Operation getWantAgent failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`Operation getWantAgent failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
}
};
...
...
@@ -402,8 +400,9 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): vo
```
js
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
function
callback
(
error
,
data
)
{
function
callback
(
error
:
BusinessError
,
data
:
void
)
{
if
(
error
)
{
console
.
error
(
`Operation stopBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
else
{
...
...
@@ -412,11 +411,11 @@ function callback(error, data) {
}
export
default
class
EntryAbility
extends
UIAbility
{
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
try
{
backgroundTaskManager
.
stopBackgroundRunning
(
this
.
context
,
callback
);
}
catch
(
error
)
{
console
.
error
(
`Operation stopBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`Operation stopBackgroundRunning failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
}
};
...
...
@@ -461,17 +460,18 @@ stopBackgroundRunning(context: Context): Promise<void>
```
js
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
export
default
class
EntryAbility
extends
UIAbility
{
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
try
{
backgroundTaskManager
.
stopBackgroundRunning
(
this
.
context
).
then
(()
=>
{
console
.
info
(
"
Operation stopBackgroundRunning succeeded
"
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`Operation stopBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`Operation stopBackgroundRunning failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`Operation stopBackgroundRunning failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
}
};
...
...
@@ -510,8 +510,9 @@ applyEfficiencyResources(request: EfficiencyResourcesRequest): void
```
js
import
backgroundTaskManager
from
'
@ohos.resourceschedule.backgroundTaskManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
request
=
{
let
request
:
backgroundTaskManager
.
EfficiencyResourcesRequest
=
{
resourceTypes
:
backgroundTaskManager
.
ResourceType
.
CPU
,
isApply
:
true
,
timeOut
:
0
,
...
...
@@ -523,7 +524,7 @@ try {
backgroundTaskManager
.
applyEfficiencyResources
(
request
);
console
.
info
(
"
applyEfficiencyResources success.
"
);
}
catch
(
error
)
{
console
.
error
(
`applyEfficiencyResources failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`applyEfficiencyResources failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
```
...
...
zh-cn/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md
浏览文件 @
f43fca76
...
...
@@ -10,7 +10,7 @@
## 导入模块
```
j
s
```
t
s
import
workScheduler
from
'
@ohos.resourceschedule.workScheduler
'
;
```
...
...
@@ -42,8 +42,8 @@ startWork(work: WorkInfo): void
**示例**
:
```
j
s
let
workInfo
=
{
```
t
s
let
workInfo
:
workScheduler
.
WorkInfo
=
{
workId
:
1
,
batteryStatus
:
workScheduler
.
BatteryStatus
.
BATTERY_STATUS_LOW
,
isRepeat
:
false
,
...
...
@@ -61,7 +61,7 @@ startWork(work: WorkInfo): void
workScheduler
.
startWork
(
workInfo
);
console
.
info
(
'
workschedulerLog startWork success
'
);
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog startwork failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`workschedulerLog startwork failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -93,8 +93,8 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
**示例**
:
```
j
s
let
workInfo
=
{
```
t
s
let
workInfo
:
workScheduler
.
WorkInfo
=
{
workId
:
1
,
batteryStatus
:
workScheduler
.
BatteryStatus
.
BATTERY_STATUS_LOW
,
isRepeat
:
false
,
...
...
@@ -112,7 +112,7 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
workScheduler
.
stopWork
(
workInfo
,
false
);
console
.
info
(
'
workschedulerLog stopWork success
'
);
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog stopWork failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`workschedulerLog stopWork failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -144,20 +144,14 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
**示例**
:
```
js
try
{
workScheduler
.
getWorkStatus
(
50
,
(
error
,
res
)
=>
{
```
ts
workScheduler
.
getWorkStatus
(
50
,
(
error
:
BusinessError
,
res
:
workScheduler
.
WorkInfo
)
=>
{
if
(
error
)
{
console
.
error
(
`workschedulerLog getWorkStatus failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
else
{
for
(
let
item
in
res
)
{
console
.
info
(
`workschedulerLog getWorkStatus success,
${
item
}
is:
${
res
[
item
]}
`
);
}
console
.
info
(
`workschedulerLog getWorkStatus success,
${
JSON
.
stringify
(
res
)}
`
);
}
});
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog getWorkStatus failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
## workScheduler.getWorkStatus
...
...
@@ -193,18 +187,12 @@ getWorkStatus(workId: number): Promise\<WorkInfo>
**示例**
:
```
js
try
{
workScheduler
.
getWorkStatus
(
50
).
then
((
res
)
=>
{
for
(
let
item
in
res
)
{
console
.
info
(
`workschedulerLog getWorkStatus success,
${
item
}
is:
${
res
[
item
]}
`
);
}
}).
catch
((
error
)
=>
{
```
ts
workScheduler
.
getWorkStatus
(
50
).
then
((
res
:
workScheduler
.
WorkInfo
)
=>
{
console
.
info
(
`workschedulerLog getWorkStatus success,
${
JSON
.
stringify
(
res
)}
`
);
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`workschedulerLog getWorkStatus failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
})
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog getWorkStatus failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
## workScheduler.obtainAllWorks
...
...
@@ -239,18 +227,14 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
**示例**
:
```
js
try
{
workScheduler
.
obtainAllWorks
((
error
,
res
)
=>
{
```
ts
workScheduler
.
obtainAllWorks
((
error
:
BusinessError
,
res
:
Array
<
workScheduler
.
WorkInfo
>
)
=>
{
if
(
error
)
{
console
.
error
(
`workschedulerLog obtainAllWorks failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
else
{
console
.
info
(
`workschedulerLog obtainAllWorks success, data is:
${
JSON
.
stringify
(
res
)}
`
);
}
});
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog obtainAllWorks failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
## workScheduler.obtainAllWorks
...
...
@@ -279,16 +263,12 @@ obtainAllWorks(): Promise\<Array\<WorkInfo>>
**示例**
:
```
js
try
{
workScheduler
.
obtainAllWorks
().
then
((
res
)
=>
{
```
ts
workScheduler
.
obtainAllWorks
().
then
((
res
:
Array
<
workScheduler
.
WorkInfo
>
)
=>
{
console
.
info
(
`workschedulerLog obtainAllWorks success, data is:
${
JSON
.
stringify
(
res
)}
`
);
}).
catch
((
e
rror
)
=>
{
}).
catch
((
error
:
BusinessE
rror
)
=>
{
console
.
error
(
`workschedulerLog obtainAllWorks failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
})
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog obtainAllWorks failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
## workScheduler.stopAndClearWorks
...
...
@@ -311,12 +291,12 @@ stopAndClearWorks(): void
**示例**
:
```
j
s
```
t
s
try
{
workScheduler
.
stopAndClearWorks
();
console
.
info
(
`workschedulerLog stopAndClearWorks success`
);
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog stopAndClearWorks failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
console
.
error
(
`workschedulerLog stopAndClearWorks failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -354,18 +334,14 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
**示例**
:
```
js
try
{
workScheduler
.
isLastWorkTimeOut
(
500
,
(
error
,
res
)
=>
{
```
ts
workScheduler
.
isLastWorkTimeOut
(
500
,
(
error
:
BusinessError
,
res
:
boolean
)
=>
{
if
(
error
)
{
console
.
error
(
`workschedulerLog isLastWorkTimeOut failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
else
{
console
.
info
(
`workschedulerLog isLastWorkTimeOut success, data is:
${
res
}
`
);
}
});
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog isLastWorkTimeOut failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
## workScheduler.isLastWorkTimeOut
...
...
@@ -401,18 +377,14 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>
**示例**
:
```
js
try
{
```
ts
workScheduler
.
isLastWorkTimeOut
(
500
)
.
then
(
res
=>
{
.
then
((
res
:
boolean
)
=>
{
console
.
info
(
`workschedulerLog isLastWorkTimeOut success, data is:
${
res
}
`
);
})
.
catch
(
error
=>
{
.
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`workschedulerLog isLastWorkTimeOut failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`workschedulerLog isLastWorkTimeOut failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
```
## WorkInfo
...
...
zh-cn/application-dev/task-management/continuous-task.md
浏览文件 @
f43fca76
...
...
@@ -103,7 +103,7 @@
private
context
:
Context
=
getContext
(
this
);
startContinuousTask
()
{
let
wantAgentInfo
:
wantAgent
.
w
antAgentInfo
=
{
let
wantAgentInfo
:
wantAgent
.
W
antAgentInfo
=
{
// 点击通知后,将要执行的动作列表
wants
:
[
{
...
...
@@ -353,7 +353,7 @@
import
{
BusinessError
}
from
'
@ohos.base
'
;
```
4.
申请和取消长时任务。在 ServiceAbility 中,调用 startBackgroundRunning() 接口和 startBackgroundRunning() 接口实现长时任务的申请和取消。
4.
申请和取消长时任务。在 ServiceAbility 中,调用 startBackgroundRunning() 接口和 startBackgroundRunning() 接口实现长时任务的申请和取消
,通过js代码实现
。
```
js
function
startContinuousTask
()
{
...
...
zh-cn/application-dev/task-management/work-scheduler.md
浏览文件 @
f43fca76
...
...
@@ -121,7 +121,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
```
ts
import
WorkSchedulerExtensionAbility
from
'
@ohos.WorkSchedulerExtensionAbility
'
;
import
workScheduler
fro
n
'
@ohos.resourceschedule.workScheduler
'
;
import
workScheduler
fro
m
'
@ohos.resourceschedule.workScheduler
'
;
```
3.
实现WorkSchedulerExtension生命周期接口。
...
...
@@ -184,8 +184,8 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
try
{
workScheduler
.
startWork
(
this
.
workInfo
);
console
.
info
(
`startWork success`
);
}
catch
(
error
:
BusinessError
)
{
console
.
error
(
`startWork failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
catch
(
error
)
{
console
.
error
(
`startWork failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -202,8 +202,8 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
try
{
workScheduler
.
stopWork
(
this
.
workInfo
);
console
.
info
(
`stopWork success`
);
}
catch
(
error
:
BusinessError
)
{
console
.
error
(
`stopWork failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
);
}
catch
(
error
)
{
console
.
error
(
`stopWork failed. code is
${
(
error
as
BusinessError
).
code
}
message is
${(
error
as
BusinessError
)
.
message
}
`
);
}
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录