提交 ba6947ca 编写于 作者: Z zhangxin_T

doc format modify

Signed-off-by: Nzhangxin_T <zhangxin312@huawei.com>
上级 9972aab6
......@@ -7,7 +7,7 @@
## 接口说明
```
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
```
......@@ -31,51 +31,60 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
## 开发步骤
1. 申请延迟挂起
```
import backgroundTaskManager from '@ohos.backgroundTaskManager';
let myReason = 'test requestSuspendDelay';
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
console.info("Request suspension delay will time out.");
});
var id = delayInfo.requestId;console.info("requestId is: " + id);
```
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
let myReason = 'test requestSuspendDelay';
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
console.info("Request suspend delay will time out.");
});
var id = delayInfo.requestId;console.info("requestId is: " + id);
```
2. 获取进入挂起前的剩余时间
```
backgroundTaskManager.getRemainingDelayTime(id).then( res => {
```js
backgroundTaskManager.getRemainingDelayTime(id).then( res => {
console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res));
}).catch( err => {
}).catch( err => {
console.log('promise => Operation failed. Cause: ' + err.data);
});
});
```
3. 取消延迟挂起
```
backgroundTaskManager.cancelSuspendDelay(id);
```
```js
backgroundTaskManager.cancelSuspendDelay(id);
```
## 开发实例
```
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
let myReason = 'test requestSuspendDelay';
// 申请延迟挂起
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
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);
// 获取应用程序进入挂起状态前的剩余时间
backgroundTaskManager.getRemainingDelayTime(id).then( res => {
console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res));
}).catch( err => {
console.log('promise => Operation failed. Cause: ' + err.data);
});
// 取消延迟挂起
backgroundTaskManager.cancelSuspendDelay(id);
```
......
......@@ -129,7 +129,7 @@ cancelSuspendDelay(requestId: number): void
## backgroundTaskManager.startBackgroundRunning
startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback&lt;void&gt;): void;
<sup>[8]</sup> startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback&lt;void&gt;): void;
向系统申请长时任务,使用callback形式返回结果。
......@@ -138,7 +138,7 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
| -------- | -------- | -------- | -------- |
| context | Context | 是 | 应用运行的上下文 |
| bgMode | BackgroundMode | 是 | 向系统申请的后台模式 |
| wantAgent | WantAgent | 是 | 通知参数,用于指定长时任务通知点击跳转的界面 |
| wantAgent | WantAgent | 是 | 通知参数,用于指定长时任务通知点击跳转的界面。使用方式参考:<sup>[8]</sup> |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回启动长时任务的结果 |
- **示例**
......@@ -176,7 +176,7 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
## backgroundTaskManager.startBackgroundRunning
startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise&lt;void&gt;
<sup>[8]</sup> startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise&lt;void&gt;
向系统申请长时任务,使用promise形式返回结果。
......@@ -223,7 +223,7 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
## backgroundTaskManager.stopBackgroundRunning
stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): void;
<sup>[8]</sup> stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): void;
向系统申请取消长时任务,使用callback形式返回结果。
......@@ -252,7 +252,7 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext(), callbac
## backgroundTaskManager.stopBackgroundRunning
stopBackgroundRunning(context: Context): Promise&lt;void&gt;;
<sup>[8]</sup> stopBackgroundRunning(context: Context): Promise&lt;void&gt;;
向系统申请取消长时任务,使用promise形式返回结果。
......@@ -279,7 +279,7 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(()
```
## BackgroundMode
## <sup>[8]</sup> BackgroundMode
| 参数名 | 参数 | 描述 |
| ----------------------- | -------- | -------- |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册