1e41f4b71Sopenharmony_ci# AppForegroundStateObserver (系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci定义应用启动和退出的状态监听,可以作为[on](js-apis-app-ability-appManager-sys.md#appmanageronappforegroundstate11)的入参监听所有应用的启动和退出的变化。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> 本模块接口为系统接口。
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 导入模块
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## 属性
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci**系统接口**: 此接口为系统接口。
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci| 名称                             | 类型                    | 可读 | 可写 | 说明   |
23e41f4b71Sopenharmony_ci| -------------------------------- | ---------------------- | ---- | ---- | ------------------ |
24e41f4b71Sopenharmony_ci| onAppStateChanged   | AsyncCallback\<void>   | 是   | 否   | 应用启动和退出状态发生变化时执行的回调函数。传入参数类型是[AppStateData](js-apis-inner-application-appStateData-sys.md)。 |
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**示例:**
27e41f4b71Sopenharmony_ci```ts
28e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit';
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_cilet observer: appManager.AppForegroundStateObserver = {
31e41f4b71Sopenharmony_ci  onAppStateChanged(appStateData) {
32e41f4b71Sopenharmony_ci    console.log(`onAppStateChanged appStateData: ${JSON.stringify(appStateData)}`);
33e41f4b71Sopenharmony_ci  },
34e41f4b71Sopenharmony_ci};
35e41f4b71Sopenharmony_ciappManager.on('appForegroundState', observer);
36e41f4b71Sopenharmony_ci```