未验证 提交 90851d9b 编写于 作者: 朱天怡 提交者: Gitee

修改

Signed-off-by: N朱天怡 <zhutianyi2@huawei.com>
上级 b166a489
...@@ -13,6 +13,13 @@ ...@@ -13,6 +13,13 @@
> **说明:** > **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
```
## backgroundTaskManager.requestSuspendDelay
## 导入模块 ## 导入模块
...@@ -21,7 +28,7 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager'; ...@@ -21,7 +28,7 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
``` ```
## backgroundTaskManager.requestSuspendDelay ## backgroundTaskManager.requestSuspendDelay<sup>(deprecated)</sup>
requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspendInfo requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspendInfo
...@@ -29,6 +36,10 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen ...@@ -29,6 +36,10 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen
延迟挂起时间一般情况下默认值为180000,低电量(依据系统低电量广播)时默认值为60000。 延迟挂起时间一般情况下默认值为180000,低电量(依据系统低电量广播)时默认值为60000。
> **说明:** 从API version 9开始废弃,建议使用[backgroundTaskManager.requestSuspendDelay](#reminderagentmanagerpublishreminder9)
>
> 从 API version 7开始支持。
**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask **系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
**参数** **参数**
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口仅可在Stage模型下使用。 > - 本模块接口仅可在Stage模型下使用。
> - 延迟任务调度约束见[延迟任务调度概述](../../task-management/work-scheduler-overview.md)。 > - 延迟任务调度约束见[延迟任务调度概述](../../task-management/work-scheduler-overview.md)。
> - 延迟任务调度错误码见[延迟任务错误码](../errorcodes/errorcode-workScheduler.md)。
## 导入模块 ## 导入模块
...@@ -18,7 +19,7 @@ import workScheduler from '@ohos.workScheduler'; ...@@ -18,7 +19,7 @@ import workScheduler from '@ohos.workScheduler';
``` ```
## workScheduler.startWork ## workScheduler.startWork
startWork(work: WorkInfo): boolean startWork(work: WorkInfo): void
通知WorkSchedulerService将工作添加到执行队列。 通知WorkSchedulerService将工作添加到执行队列。
...@@ -30,12 +31,6 @@ startWork(work: WorkInfo): boolean ...@@ -30,12 +31,6 @@ startWork(work: WorkInfo): boolean
| ---- | --------------------- | ---- | -------------- | | ---- | --------------------- | ---- | -------------- |
| work | [WorkInfo](#workinfo) | 是 | 指示要添加到执行队列的工作。 | | work | [WorkInfo](#workinfo) | 是 | 指示要添加到执行队列的工作。 |
**返回值**
| 类型 | 说明 |
| ------- | -------------------------------- |
| boolean | 如果工作成功添加到执行队列,则返回true,否则返回false。 |
**示例** **示例**
```js ```js
...@@ -53,12 +48,16 @@ startWork(work: WorkInfo): boolean ...@@ -53,12 +48,16 @@ startWork(work: WorkInfo): boolean
mykey3: 1.5 mykey3: 1.5
} }
} }
var res = workScheduler.startWork(workInfo); try{
console.info(`workschedulerLog res: ${res}`); workScheduler.startWork(workInfo);
console.info('workschedulerLog startWork success');
} catch (error) {
console.error(`workschedulerLog startwork failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.stopWork ## workScheduler.stopWork
stopWork(work: WorkInfo, needCancel?: boolean): boolean stopWork(work: WorkInfo, needCancel?: boolean): void
通知WorkSchedulerService停止指定工作。 通知WorkSchedulerService停止指定工作。
...@@ -71,12 +70,6 @@ stopWork(work: WorkInfo, needCancel?: boolean): boolean ...@@ -71,12 +70,6 @@ stopWork(work: WorkInfo, needCancel?: boolean): boolean
| work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 | | work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 |
| needCancel | boolean | 是 | 是否需要取消的工作。 | | needCancel | boolean | 是 | 是否需要取消的工作。 |
**返回值**
| 类型 | 说明 |
| ------- | ----------------------- |
| boolean | 如果成功,则返回true,否则返回false。 |
**示例** **示例**
```js ```js
...@@ -94,8 +87,12 @@ stopWork(work: WorkInfo, needCancel?: boolean): boolean ...@@ -94,8 +87,12 @@ stopWork(work: WorkInfo, needCancel?: boolean): boolean
mykey3: 1.5 mykey3: 1.5
} }
} }
var res = workScheduler.stopWork(workInfo, false); try{
console.info(`workschedulerLog res: ${res}`); workScheduler.stopWork(workInfo, false);
console.info('workschedulerLog stopWork success');
} catch (error) {
console.error(`workschedulerLog stopWork failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
...@@ -115,15 +112,19 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void ...@@ -115,15 +112,19 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
**示例** **示例**
```js ```js
workScheduler.getWorkStatus(50, (err, res) => { try{
if (err) { workScheduler.getWorkStatus(50, (error, res) => {
console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`); if (error) {
} else { console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
for (let item in res) { } else {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
} }
} });
}); } catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
...@@ -148,13 +149,17 @@ getWorkStatus(workId: number): Promise\<WorkInfo> ...@@ -148,13 +149,17 @@ getWorkStatus(workId: number): Promise\<WorkInfo>
**示例** **示例**
```js ```js
workScheduler.getWorkStatus(50).then((res) => { try{
for (let item in res) { workScheduler.getWorkStatus(50).then((res) => {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); for (let item in res) {
} console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}).catch((err) => { }
console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`); }).catch((error) => {
}) 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 ## workScheduler.obtainAllWorks
...@@ -179,13 +184,17 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo> ...@@ -179,13 +184,17 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
**示例** **示例**
```js ```js
workScheduler.obtainAllWorks((err, res) =>{ try{
if (err) { workScheduler.obtainAllWorks((error, res) =>{
console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`); if (error) {
} else { console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); } 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 ## workScheduler.obtainAllWorks
...@@ -204,15 +213,19 @@ obtainAllWorks(): Promise<Array\<WorkInfo>> ...@@ -204,15 +213,19 @@ obtainAllWorks(): Promise<Array\<WorkInfo>>
**示例** **示例**
```js ```js
workScheduler.obtainAllWorks().then((res) => { try{
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); workScheduler.obtainAllWorks().then((res) => {
}).catch((err) => { console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`); }).catch((error) => {
}) 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 ## workScheduler.stopAndClearWorks
stopAndClearWorks(): boolean stopAndClearWorks(): void
停止和取消与当前应用程序关联的所有工作。 停止和取消与当前应用程序关联的所有工作。
...@@ -221,8 +234,12 @@ stopAndClearWorks(): boolean ...@@ -221,8 +234,12 @@ stopAndClearWorks(): boolean
**示例** **示例**
```js ```js
let res = workScheduler.stopAndClearWorks(); try{
console.info(`workschedulerLog res: ${res}`); workScheduler.stopAndClearWorks();
console.info(`workschedulerLog stopAndClearWorks success`);
} catch (error) {
console.error(`workschedulerLog stopAndClearWorks failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.isLastWorkTimeOut ## workScheduler.isLastWorkTimeOut
...@@ -248,13 +265,17 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean ...@@ -248,13 +265,17 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
**示例** **示例**
```js ```js
workScheduler.isLastWorkTimeOut(500, (err, res) =>{ try{
if (err) { workScheduler.isLastWorkTimeOut(500, (error, res) =>{
console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`); if (error) {
} else { onsole.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); } 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 ## workScheduler.isLastWorkTimeOut
...@@ -279,13 +300,17 @@ isLastWorkTimeOut(workId: number): Promise\<boolean> ...@@ -279,13 +300,17 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>
**示例** **示例**
```js ```js
workScheduler.isLastWorkTimeOut(500) try{
.then(res => { workScheduler.isLastWorkTimeOut(500)
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); .then(res => {
}) console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
.catch(err => { })
console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`); .catch(error => {
}); 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 ## WorkInfo
......
...@@ -40,7 +40,7 @@ Memory operation failed. ...@@ -40,7 +40,7 @@ Memory operation failed.
## 9800002 Parcel读写操作失败 ## 9800002 Parcel读写操作失败
### 错误信息 ### 错误信息
The number of reminders exceeds the limit. Parcel operation failed.
### 可能原因 ### 可能原因
1. 调用MessageParcel对象读取或写入对象异常 1. 调用MessageParcel对象读取或写入对象异常
...@@ -62,7 +62,7 @@ Inner transact failed. ...@@ -62,7 +62,7 @@ Inner transact failed.
## 9800004 系统服务失败 ## 9800004 系统服务失败
### 错误信息 ### 错误信息
Inner transact failed. System service operation failed.
### 可能原因 ### 可能原因
1. 系统服务还未启动 1. 系统服务还未启动
......
...@@ -29,7 +29,7 @@ Memory operation failed. ...@@ -29,7 +29,7 @@ Memory operation failed.
## 9700002 Parcel读写操作失败 ## 9700002 Parcel读写操作失败
### 错误信息 ### 错误信息
The number of reminders exceeds the limit. Parcel operation failed.
### 可能原因 ### 可能原因
1. 调用MessageParcel对象读取或写入对象异常 1. 调用MessageParcel对象读取或写入对象异常
...@@ -40,7 +40,7 @@ The number of reminders exceeds the limit. ...@@ -40,7 +40,7 @@ The number of reminders exceeds the limit.
## 9700003 系统服务失败 ## 9700003 系统服务失败
### 错误信息 ### 错误信息
Inner transact failed. System service operation failed.
### 可能原因 ### 可能原因
1. 系统服务还未启动 1. 系统服务还未启动
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册