1# AppStateData 2<!--Kit: Ability Kit--> 3<!--Subsystem: Ability--> 4<!--Owner: @SKY2001--> 5<!--Designer: @yzkp--> 6<!--Tester: @lixueqing513--> 7<!--Adviser: @huipeizi--> 8 9The module defines the application state data, which can be obtained through [appManager.on('applicationState')](./js-apis-app-ability-appManager.md#appmanageronapplicationstate14). 10 11> **NOTE** 12> 13> The initial APIs of this module are supported since API version 14. Newly added APIs will be marked with a superscript to indicate their earliest API version. 14 15## Modules to Import 16 17```ts 18import { appManager } from '@kit.AbilityKit'; 19``` 20 21## Properties 22 23**System capability**: SystemCapability.Ability.AbilityRuntime.Core 24 25| Name | Type | Mandatory | Description | 26| ------------------------- | ------ | ---- | --------- | 27| bundleName | string | Yes | Bundle name.| 28| uid | number | Yes | UID of the application. | 29| state | number | Yes | Application state.<br>**0**: The application is being initialized.<br>**1**: The application has been initialized and is ready.<br>**2**: The application is running in the foreground.<br>**3**: The application is having the focus. (This state is reserved.)<br>**4**: The application is running in the background.<br>**5**: The application has exited.| 30| isSplitScreenMode | boolean | Yes| Whether the application is in split-screen mode.<br>**true**: The application is in split-screen mode.<br>**false**: The application is not in split-screen mode.| 31| isFloatingWindowMode | boolean | Yes| Whether the application is in floating window mode.<br>**true**: The application is in floating window mode.<br>**false**: The application is not in floating window mode.| 32 33**Example** 34 35```ts 36import { appManager } from '@kit.AbilityKit'; 37import { BusinessError } from '@kit.BasicServicesKit'; 38 39let applicationStateObserver: appManager.ApplicationStateObserver = { 40 onForegroundApplicationChanged(appStateData) { 41 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 42 console.log(`appStateData.bundleName: ${appStateData.bundleName}`); 43 console.log(`appStateData.uid: ${appStateData.uid}`); 44 console.log(`appStateData.state: ${appStateData.state}`); 45 console.log(`appStateData.isSplitScreenMode: ${appStateData.isSplitScreenMode}`); 46 console.log(`appStateData.isFloatingWindowMode: ${appStateData.isFloatingWindowMode}`); 47 }, 48 onAbilityStateChanged(abilityStateData) { 49 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 50 }, 51 onProcessCreated(processData) { 52 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 53 }, 54 onProcessDied(processData) { 55 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 56 }, 57 onProcessStateChanged(processData) { 58 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 59 }, 60 onAppStarted(appStateData) { 61 console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 62 }, 63 onAppStopped(appStateData) { 64 console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 65 } 66}; 67 68try { 69 const observerId = appManager.on('applicationState', applicationStateObserver); 70 console.log(`[appManager] observerCode: ${observerId}`); 71} catch (paramError) { 72 let code = (paramError as BusinessError).code; 73 let message = (paramError as BusinessError).message; 74 console.error(`[appManager] error: ${code}, ${message}`); 75} 76``` 77