1e41f4b71Sopenharmony_ci# ApplicationStateObserver (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe ApplicationStateObserver module defines an observer to listen for application state changes. It can be used as an input parameter in [on](js-apis-app-ability-appManager-sys.md#appmanageronapplicationstate) to listen for lifecycle changes of the current application.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci> 
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 8. 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## Properties
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci| Name                            | Type                   | Readable| Writable| Description  |
23e41f4b71Sopenharmony_ci| -------------------------------- | ---------------------- | ---- | ---- | ------------------ |
24e41f4b71Sopenharmony_ci| onForegroundApplicationChanged   | AsyncCallback\<void>   | Yes  | No  | Callback invoked when the foreground or background state of an application changes. The parameter type passed in is [AppStateData](js-apis-inner-application-appStateData-sys.md).|
25e41f4b71Sopenharmony_ci| onAbilityStateChanged            | AsyncCallback\<void>   | Yes  | No | Callback invoked when the ability state changes. The parameter type passed in is [AbilityStateData](js-apis-inner-application-abilityStateData-sys.md).  |
26e41f4b71Sopenharmony_ci| onProcessCreated                 | AsyncCallback\<void>   | Yes  | No  | Callback invoked when a process is created. The parameter type passed in is [ProcessData](js-apis-inner-application-processData-sys.md).         |
27e41f4b71Sopenharmony_ci| onProcessDied                     | AsyncCallback\<void>   | Yes  | No  | Callback invoked when a process is destroyed. The parameter type passed in is [ProcessData](js-apis-inner-application-processData-sys.md).         |
28e41f4b71Sopenharmony_ci| onProcessStateChanged<sup>9+</sup> | AsyncCallback\<void>   | Yes  | No  | Callback invoked when the process state is changed. The parameter type passed in is [ProcessData](js-apis-inner-application-processData-sys.md).       |
29e41f4b71Sopenharmony_ci| onAppStarted<sup>12+</sup>       | AsyncCallback\<void>   | Yes  | No  | Callback invoked when the first process of the application is created. The parameter type passed in is [AppStateData](js-apis-inner-application-appStateData-sys.md).    |
30e41f4b71Sopenharmony_ci| onAppStopped<sup>12+</sup>       | AsyncCallback\<void>   | Yes  | No  | Callback invoked when the last process of the application is destroyed. The parameter type passed in is [AppStateData](js-apis-inner-application-appStateData-sys.md).    |
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**Example**
33e41f4b71Sopenharmony_ci```ts
34e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit';
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_cilet applicationStateObserver: appManager.ApplicationStateObserver = {
37e41f4b71Sopenharmony_ci  onForegroundApplicationChanged(appStateData) {
38e41f4b71Sopenharmony_ci    console.log(`onForegroundApplicationChanged appStateData: ${JSON.stringify(appStateData)}`);
39e41f4b71Sopenharmony_ci  },
40e41f4b71Sopenharmony_ci  onAbilityStateChanged(abilityStateData) {
41e41f4b71Sopenharmony_ci    console.log(`onAbilityStateChanged onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
42e41f4b71Sopenharmony_ci  },
43e41f4b71Sopenharmony_ci  onProcessCreated(processData) {
44e41f4b71Sopenharmony_ci    console.log(`onProcessCreated onProcessCreated: ${JSON.stringify(processData)}`);
45e41f4b71Sopenharmony_ci  },
46e41f4b71Sopenharmony_ci  onProcessDied(processData) {
47e41f4b71Sopenharmony_ci    console.log(`onProcessDied onProcessDied: ${JSON.stringify(processData)}`);
48e41f4b71Sopenharmony_ci  },
49e41f4b71Sopenharmony_ci  onProcessStateChanged(processData) {
50e41f4b71Sopenharmony_ci    console.log(`onProcessStateChanged onProcessStateChanged: ${JSON.stringify(processData)}`);
51e41f4b71Sopenharmony_ci  },
52e41f4b71Sopenharmony_ci  onAppStarted(appStateData) {
53e41f4b71Sopenharmony_ci    console.log(`onAppStarted appStateData: ${JSON.stringify(appStateData)}`);
54e41f4b71Sopenharmony_ci  },
55e41f4b71Sopenharmony_ci  onAppStopped(appStateData) {
56e41f4b71Sopenharmony_ci    console.log(`onAppStopped appStateData: ${JSON.stringify(appStateData)}`);
57e41f4b71Sopenharmony_ci  }
58e41f4b71Sopenharmony_ci};
59e41f4b71Sopenharmony_cilet observerCode = appManager.on('applicationState', applicationStateObserver);
60e41f4b71Sopenharmony_ci```
61