提交 73f4d926 编写于 作者: J jsjzju

同步接口整改

Signed-off-by: Njsjzju <jinsenjun@huawei.com>
Change-Id: Ifd6ffe049ef4d91d89d7f88b8e5578fb24484e58
上级 a83d353a
......@@ -389,12 +389,16 @@ appManager.isSharedBundleRunning(bundleName, versionCode, (err, data) => {
});
```
## appManager.on
## appManager.on(type: 'applicationState', observer: ApplicationStateObserver)<sup>(deprecated)</sup>
on(type: 'applicationState', observer: ApplicationStateObserver): number;
注册全部应用程序的状态观测器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[appManager.on(type: 'applicationStateEvent', observer: ApplicationStateObserver)](#appmanagerontype-applicationstateevent-observer-applicationstateobserver10)。
**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -452,12 +456,16 @@ try {
}
```
## appManager.on
## appManager.on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>)<sup>(deprecated)</sup>
on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
注册指定应用程序的状态观测器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[appManager.on(type: 'applicationStateEvent', observer: ApplicationStateObserver, bundleNameList: Array\<string>)](#appmanagerontype-applicationstateevent-observer-applicationstateobserver-bundlenamelist-arraystring10)。
**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -517,12 +525,16 @@ try {
}
```
## appManager.off
## appManager.off(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>)<sup>(deprecated)</sup>
off(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>): void;
取消注册应用程序状态观测器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[appManager.off(type: 'applicationStateEvent', observerId: number)](#appmanagerofftype-applicationstateevent-observerid-number10)。
**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -593,12 +605,16 @@ try {
}
```
## appManager.off
## appManager.off(type: 'applicationState', observerId: number)<sup>(deprecated)</sup>
off(type: 'applicationState', observerId: number): Promise\<void>;
取消注册应用程序状态观测器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[appManager.off(type: 'applicationStateEvent', observerId: number)](#appmanagerofftype-applicationstateevent-observerid-number10)。
**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -671,6 +687,203 @@ try {
}
```
## appManager.on(type: 'applicationStateEvent', observer: ApplicationStateObserver)<sup>10+</sup>
on(type: 'applicationStateEvent', observer: ApplicationStateObserver): number;
注册全部应用程序的状态观测器。
**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填'applicationStateEvent'字符串。 |
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
**返回值:**
| 类型 | 说明 |
| --- | --- |
| number | 已注册观测器的数字代码,可用于off接口取消注册观测器。|
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
import appManager from '@ohos.app.ability.appManager';
let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
},
onAbilityStateChanged(abilityStateData) {
console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
},
onProcessCreated(processData) {
console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
},
onProcessDied(processData) {
console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
},
onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
};
try {
const observerId = appManager.on('applicationStateEvent', applicationStateObserver);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.error(`[appManager] error: ${paramError.code}, ${paramError.message} `);
}
```
## appManager.on(type: 'applicationStateEvent', observer: ApplicationStateObserver, bundleNameList: Array\<string>)<sup>10+</sup>
on(type: 'applicationStateEvent', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
注册指定应用程序的状态观测器。
**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填'applicationStateEvent'字符串。 |
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
| bundleNameList | `Array<string>` | 是 | 表示需要注册监听的bundleName数组。最大值128。 |
**返回值:**
| 类型 | 说明 |
| --- | --- |
| number | 已注册观测器的数字代码,可用于off接口注销观测器。|
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
import appManager from '@ohos.app.ability.appManager';
let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
},
onAbilityStateChanged(abilityStateData) {
console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
},
onProcessCreated(processData) {
console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
},
onProcessDied(processData) {
console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
},
onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
};
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
const observerId = appManager.on('applicationStateEvent', applicationStateObserver, bundleNameList);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.error(`[appManager] error: ${paramError.code}, ${paramError.message} `);
}
```
## appManager.off(type: 'applicationStateEvent', observerId: number)<sup>10+</sup>
off(type: 'applicationStateEvent', observerId: number): void;
取消注册应用程序状态观测器。
**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填'applicationStateEvent'字符串。 |
| observerId | number | 是 | 表示观测器的编号代码。 |
| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
import appManager from '@ohos.app.ability.appManager';
let observerId = 0;
// 1.注册应用状态监听器
let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
},
onAbilityStateChanged(abilityStateData) {
console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
},
onProcessCreated(processData) {
console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
},
onProcessDied(processData) {
console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
},
onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
};
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
observerId = appManager.on('applicationStateEvent', applicationStateObserver, bundleNameList);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.error(`[appManager] error: ${paramError.code}, ${paramError.message} `);
}
// 2.注销应用状态监听器
try {
appManager.off('applicationStateEvent', observerId);
} catch (paramError) {
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
```
## appManager.getForegroundApplications
getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
......@@ -1356,3 +1569,4 @@ try {
| STATE_ACTIVE | 3 | 当进程在获焦的时候处于的状态。 |
| STATE_BACKGROUND | 4 | 当进程处于后台不可见时处于的状态。 |
| STATE_DESTROY | 5 | 当进程在销毁的时候处于的状态。 |
<!--no_check-->
\ No newline at end of file
......@@ -11,12 +11,16 @@ ErrorManager模块提供对错误观察器的注册和注销的能力。使用
import errorManager from '@ohos.app.ability.errorManager';
```
## ErrorManager.on
## ErrorManager.on(type: 'error', observer: ErrorObserver)<sup>(deprecated)</sup>
on(type: 'error', observer: ErrorObserver): number;
注册错误观测器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[ErrorManager.on(type: 'errorEvent', observer: ErrorObserver)](#errormanagerontype-errorevent-observer-errorobserver10)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
......@@ -59,16 +63,20 @@ let observerId = -1;
try {
observerId = errorManager.on('error', observer);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
```
## ErrorManager.off
## ErrorManager.off(type: 'error', observerId: number, callback: AsyncCallback\<void>)<sup>(deprecated)</sup>
off(type: 'error', observerId: number, callback: AsyncCallback\<void>): void;
注销错误观测器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[ErrorManager.off(type: 'errorEvent', observerId: number)](#errormanagerofftype-errorevent-observerid-number10)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
......@@ -100,16 +108,20 @@ function unregisterErrorObserverCallback(err) {
try {
errorManager.off('error', observerId, unregisterErrorObserverCallback);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
```
## ErrorManager.off
## ErrorManager.off(type: 'error', observerId: number)<sup>(deprecated)</sup>
off(type: 'error', observerId: number): Promise\<void>;
注销错误观测器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[ErrorManager.off(type: 'errorEvent', observerId: number)](#errormanagerofftype-errorevent-observerid-number10)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
......@@ -146,7 +158,96 @@ try {
console.error('----------- unregisterErrorObserver fail ----------', err);
});
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
```
## ErrorManager.on(type: 'errorEvent', observer: ErrorObserver)<sup>10+</sup>
on(type: 'errorEvent', observer: ErrorObserver): number;
注册错误观测器。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 填写'errorEvent',表示错误观察器。 |
| observer | [ErrorObserver](./js-apis-inner-application-errorObserver.md) | 是 | 错误观察器。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 观察器的index值,和观察器一一对应。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000003 | Id does not exist. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg);
},
onException(errorObj) {
console.log('onException, name: ', errorObj.name);
console.log('onException, message: ', errorObj.message);
if (typeof(errorObj.stack) === 'string') {
console.log('onException, stack: ', errorObj.stack);
}
}
};
let observerId = -1;
try {
observerId = errorManager.on('errorEvent', observer);
} catch (paramError) {
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
```
## ErrorManager.off(type: 'errorEvent', observerId: number)<sup>10+</sup>
off(type: 'errorEvent', observerId: number): void;
注销错误观测器。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 填写'errorEvent',表示错误观察器。 |
| observerId | number | 是 | 由on方法返回的观察器的index值。 |
| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000003 | Id does not exist. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
let observerId = 100;
try {
errorManager.off('errorEvent', observerId);
} catch (paramError) {
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
```
<!--no_check-->
\ No newline at end of file
......@@ -16,12 +16,16 @@ import missionManager from '@ohos.app.ability.missionManager';
ohos.permission.MANAGE_MISSIONS
## missionManager.on
## missionManager.on(type:'mission', listener: MissionListener)<sup>(deprecated)</sup>
on(type:'mission', listener: MissionListener): number;
注册系统任务状态监听器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[missionManager.on(type:'missionEvent', listener: MissionListener)](#missionmanagerontypemissionevent-listener-missionlistener10)。
**需要权限**:ohos.permission.MANAGE_MISSIONS
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
......@@ -32,6 +36,7 @@ on(type:'mission', listener: MissionListener): number;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填'mission'字符串。 |
| listener | [MissionListener](js-apis-inner-application-missionListener.md) | 是 | 系统任务监听器。 |
**返回值:**
......@@ -73,7 +78,7 @@ export default class EntryAbility extends UIAbility {
});
}
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
console.log('[Demo] EntryAbility onDestroy');
}
......@@ -84,15 +89,15 @@ export default class EntryAbility extends UIAbility {
try {
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`);
return;
}
console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`);
});
if (globalThis.flag) {
......@@ -102,13 +107,16 @@ export default class EntryAbility extends UIAbility {
};
```
## missionManager.off
## missionManager.off(type: 'mission', listenerId: number, callback: AsyncCallback&lt;void&gt;)<sup>(deprecated)</sup>
off(type: 'mission', listenerId: number, callback: AsyncCallback&lt;void&gt;): void;
解注册任务状态监听器。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[missionManager.off(type: 'missionEvent', listenerId: number)](#missionmanagerofftype-missionevent-listenerid-number10)。
**需要权限**:ohos.permission.MANAGE_MISSIONS
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
......@@ -119,6 +127,7 @@ off(type: 'mission', listenerId: number, callback: AsyncCallback&lt;void&gt;): v
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填'mission'字符串。 |
| listenerId | number | 是 | 系统任务状态监器法的index值,和监听器一一对应,由on方法返回。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 执行结果回调函数。 |
......@@ -163,7 +172,7 @@ export default class EntryAbility extends UIAbility {
});
}
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
console.log('[Demo] EntryAbility onDestroy');
}
......@@ -174,15 +183,15 @@ export default class EntryAbility extends UIAbility {
try {
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`);
return;
}
console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`);
});
if (globalThis.flag) {
......@@ -192,13 +201,16 @@ export default class EntryAbility extends UIAbility {
};
```
## missionManager.off
## missionManager.off(type: 'mission', listenerId: number)<sup>(deprecated)</sup>
off(type: 'mission', listenerId: number): Promise&lt;void&gt;;
解注册任务状态监听,以promise方式返回执行结果。
> **说明:**
>
> 从 API version 9开始支持,从API version 10开始废弃,推荐使用[missionManager.off(type: 'missionEvent', listenerId: number)](#missionmanagerofftype-missionevent-listenerid-number10)。
**需要权限**:ohos.permission.MANAGE_MISSIONS
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
......@@ -209,6 +221,7 @@ off(type: 'mission', listenerId: number): Promise&lt;void&gt;;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填'mission'字符串。 |
| listenerId | number | 是 | 系统任务状态监听器的index值,和监听器一一对应,由on方法返回。 |
**返回值:**
......@@ -258,7 +271,7 @@ export default class EntryAbility extends UIAbility {
});
}
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
console.log('[Demo] EntryAbility onDestroy');
}
......@@ -269,15 +282,100 @@ export default class EntryAbility extends UIAbility {
try {
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`);
return;
}
console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`);
});
if (globalThis.flag) {
return;
}
}
};
```
## missionManager.on(type:'missionEvent', listener: MissionListener)<sup>10+</sup>
on(type:'missionEvent', listener: MissionListener): number;
注册系统任务状态监听器。
**需要权限**:ohos.permission.MANAGE_MISSIONS
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
**系统API**: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填'missionEvent'字符串。 |
| listener | [MissionListener](js-apis-inner-application-missionListener.md) | 是 | 系统任务监听器。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 监听器的index值,由系统创建,在注册系统任务状态监听时分配,和监听器一一对应&nbsp;。 |
**示例:**
```ts
import missionManager from '@ohos.app.ability.missionManager';
import UIAbility from '@ohos.app.ability.UIAbility';
let listener = {
onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');},
onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');},
onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');},
onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');},
onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');},
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');},
onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
};
let listenerId = -1;
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('[Demo] EntryAbility onCreate');
globalThis.abilityWant = want;
globalThis.context = this.context;
}
onDestroy() {
try {
if (listenerId !== -1) {
missionManager.off('missionEvent', listenerId);
}
} catch (paramError) {
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
console.log('[Demo] EntryAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log('[Demo] EntryAbility onWindowStageCreate');
try {
listenerId = missionManager.on('missionEvent', listener);
} catch (paramError) {
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`);
return;
}
console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`);
});
if (globalThis.flag) {
......@@ -287,6 +385,93 @@ export default class EntryAbility extends UIAbility {
};
```
## missionManager.off(type: 'missionEvent', listenerId: number)<sup>10+</sup>
off(type: 'missionEvent', listenerId: number): void;
解注册任务状态监听器。
**需要权限**:ohos.permission.MANAGE_MISSIONS
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
**系统API**: 此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填'missionEvent'字符串。 |
| listenerId | number | 是 | 系统任务状态监器法的index值,和监听器一一对应,由on方法返回。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 执行结果回调函数。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16300002 | Input error. The specified mission listener does not exist. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
import missionManager from '@ohos.app.ability.missionManager';
import UIAbility from '@ohos.app.ability.UIAbility';
let listener = {
onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');},
onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');},
onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');},
onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');},
onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');},
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');},
onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
};
let listenerId = -1;
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('[Demo] EntryAbility onCreate');
globalThis.abilityWant = want;
globalThis.context = this.context;
}
onDestroy() {
try {
if (listenerId !== -1) {
missionManager.off('missionEvent', listenerId);
}
} catch (paramError) {
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
console.log('[Demo] EntryAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log('[Demo] EntryAbility onWindowStageCreate');
try {
listenerId = missionManager.on('missionEvent', listener);
} catch (paramError) {
console.error(`error: ${paramError.code}, ${paramError.message}`);
}
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`);
return;
}
console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`);
});
if (globalThis.flag) {
return;
}
}
};
```
## missionManager.getMissionInfo
......@@ -1409,4 +1594,5 @@ try {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
\ No newline at end of file
```
<!--no_check-->
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册