提交 ba6947ca 编写于 作者: Z zhangxin_T

doc format modify

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