1e41f4b71Sopenharmony_ci# AppForegroundStateObserver (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe AppForegroundStateObserver module defines the listener used to listen for application startup and exit state changes. It can be used as an input parameter of [on](js-apis-app-ability-appManager-sys.md#appmanageronappforegroundstate11) to listen for the state changes of all applications.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Modules to Import
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## Attributes
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci**System API**: This is a system API.
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci| Name                            | Type                   | Readable| Writable| Description  |
23e41f4b71Sopenharmony_ci| -------------------------------- | ---------------------- | ---- | ---- | ------------------ |
24e41f4b71Sopenharmony_ci| onAppStateChanged   | AsyncCallback\<void>   | Yes  | No  | Callback invoked when the startup or exit state of an application changes. The parameter type passed in is [AppStateData](js-apis-inner-application-appStateData-sys.md).|
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**Example**
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```
37