1# AppForegroundStateObserver 2 3The **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.md#appmanageron11) to listen for the state changes of all applications. 4 5> **NOTE** 6> 7> 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. 8> The APIs provided by this module are system APIs. 9 10## Modules to Import 11 12```ts 13import appManager from '@ohos.app.ability.appManager'; 14``` 15 16## Attributes 17 18**System capability**: SystemCapability.Ability.AbilityRuntime.Core 19 20| Name | Type | Readable| Writable| Description | 21| -------------------------------- | ---------------------- | ---- | ---- | ------------------ | 22| 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.md).| 23 24**Example** 25```ts 26import appManager from '@ohos.app.ability.appManager'; 27 28let observer: appManager.AppForegroundStateObserver = { 29 onAppStateChanged(appStateData) { 30 console.log(`onAppStateChanged appStateData: ${JSON.stringify(appStateData)}`); 31 }, 32}; 33appManager.on('appForegroundState', observer); 34``` 35