提交 9a2fd682 编写于 作者: X xinking129

Supplementary doc document description

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 fc08582e
...@@ -21,6 +21,32 @@ onApplicationForeground(): void; ...@@ -21,6 +21,32 @@ onApplicationForeground(): void;
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
globalThis.applicationStateChangeCallback = {
onApplicationForeground() {
console.info('applicationStateChangeCallback onApplicationForeground');
}
}
export default class MyAbility extends UIAbility {
onCreate() {
console.log('MyAbility onCreate');
globalThis.applicationContext = this.context.getApplicationContext();
// 1.获取applicationContext
let applicationContext = globalThis.applicationContext;
// 2.通过applicationContext注册应用前后台状态监听
applicationContext.on('applicationStateChange', globalThis.ApplicationStateChangeCallback);
}
onDestroy() {
let applicationContext = globalThis.applicationContext;
// 1.通过applicationContext解除注册应用前后台状态监听
applicationContext.off('applicationStateChange', globalThis.ApplicationStateChangeCallback);
}
}
```
## ApplicationStateChangeCallback.onApplicationBackground ## ApplicationStateChangeCallback.onApplicationBackground
onApplicationBackground(): void; onApplicationBackground(): void;
...@@ -35,9 +61,6 @@ onApplicationBackground(): void; ...@@ -35,9 +61,6 @@ onApplicationBackground(): void;
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
globalThis.applicationStateChangeCallback = { globalThis.applicationStateChangeCallback = {
onApplicationForeground() {
console.info('applicationStateChangeCallback onApplicationForeground');
},
onApplicationBackground() { onApplicationBackground() {
console.info('applicationStateChangeCallback onApplicationBackground'); console.info('applicationStateChangeCallback onApplicationBackground');
} }
......
...@@ -291,8 +291,8 @@ on(type: 'applicationStateChange', callback: ApplicationStateChangeCallback): ** ...@@ -291,8 +291,8 @@ on(type: 'applicationStateChange', callback: ApplicationStateChangeCallback): **
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ---------------- | | -------- | ------------------------------------------------------------ | ---- | ---------------- |
| type | 'applicationStateChange' | 是 | 监听事件的类型。 | | type | string | 是 | 监听事件类型,必须为'applicationStateChange'。 |
| callback | [ApplicationStateChangeCallback](#js-apis-app-ability-applicationStateChangeCallback.md) | 是 | 回调方法。 | | callback | [ApplicationStateChangeCallback](#js-apis-app-ability-applicationStateChangeCallback.md) | 是 | 对于该事件监听的回调方法,可以对应用从后台切换到前台,以及前台切换到后台分别定义回调。 |
**示例:** **示例:**
...@@ -325,7 +325,7 @@ export default class MyAbility extends UIAbility { ...@@ -325,7 +325,7 @@ export default class MyAbility extends UIAbility {
off(type: 'applicationStateChange', callback: AsyncCallback<**void**>): **void**; off(type: 'applicationStateChange', callback: AsyncCallback<**void**>): **void**;
取消对当前应用前后台变化的监听。删除指定callback对应的注册监听。 取消当前应用指定的前后台变化的监听。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
...@@ -333,7 +333,7 @@ off(type: 'applicationStateChange', callback: AsyncCallback<**void**>): **void** ...@@ -333,7 +333,7 @@ off(type: 'applicationStateChange', callback: AsyncCallback<**void**>): **void**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | -------------------------------- | | -------- | ------------------------ | ---- | -------------------------------- |
| type | 'applicationStateChange' | 是 | 取消监听事件的类型。 | | type | string | 是 | 取消监听事件的类型,必须为'applicationStateChange'。 |
| callback | AsyncCallback\<void> | 否 | 删除指定callback对应的注册监听。 | | callback | AsyncCallback\<void> | 否 | 删除指定callback对应的注册监听。 |
**示例:** **示例:**
...@@ -361,7 +361,7 @@ export default class EntryAbility extends UIAbility { ...@@ -361,7 +361,7 @@ export default class EntryAbility extends UIAbility {
off(type: 'applicationStateChange'): **void**; off(type: 'applicationStateChange'): **void**;
取消对当前应用前后台变化的监听。删除全部的注册监听。 取消当前应用注册的前后台变化的全部监听。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
...@@ -369,7 +369,7 @@ off(type: 'applicationStateChange'): **void**; ...@@ -369,7 +369,7 @@ off(type: 'applicationStateChange'): **void**;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------- | ---- | -------------------- | | ------ | ------------- | ---- | -------------------- |
| type | 'applicationStateChange' | 是 | 取消监听事件的类型。 | | type | string | 是 | 取消监听事件的类型,必须为'applicationStateChange'。 |
**示例:** **示例:**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册