1# AppForegroundStateObserver (System API) 2<!--Kit: Ability Kit--> 3<!--Subsystem: Ability--> 4<!--Owner: @SKY2001--> 5<!--Designer: @yzkp--> 6<!--Tester: @lixueqing513--> 7<!--Adviser: @huipeizi--> 8 9The 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. 10 11> **NOTE** 12> 13> 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. 14> The APIs provided by this module are system APIs. 15 16## Modules to Import 17 18```ts 19import { appManager } from '@kit.AbilityKit'; 20``` 21 22## AppForegroundStateObserver 23 24### onAppStateChanged 25 26onAppStateChanged(appStateData: AppStateData): void 27 28Called when the application launch or exit state changes. 29 30**System capability**: SystemCapability.Ability.AbilityRuntime.Core 31 32**System API**: This is a system API. 33 34**Parameters** 35 36| Name | Type| Mandatory| Description | 37| ------ | ---- | ---- | ----- | 38| appStateData | [AppStateData](js-apis-inner-application-appStateData.md) | Yes | Application state data.| 39 40**Example** 41```ts 42import { appManager } from '@kit.AbilityKit'; 43 44let observer: appManager.AppForegroundStateObserver = { 45 onAppStateChanged(appStateData) { 46 console.info(`onAppStateChanged appStateData: ${JSON.stringify(appStateData)}`); 47 }, 48}; 49appManager.on('appForegroundState', observer); 50``` 51