# AppLifecycleManagement **Repository Path**: gorit/AppLifecycleManagement ## Basic Information - **Project Name**: AppLifecycleManagement - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 9 - **Created**: 2025-04-30 - **Last Updated**: 2025-05-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Application Lifecycle State Management ## Overview This sample introduces how to exit and restart an application, switch an application to the background, and subscribe to the state change of the application in the case of foreground-and-background switchover. ## Preview ![preview.en.png](screenshots/devices/preview.en.png) ## Project Directory ``` ├──entry/src/main/ets/ │ ├──common │ │ ├──ToastUtils.ets // Toast utilities │ │ └──Logger.ets // Logger │ ├──entryability │ │ └──EntryAbility.ets // Entry ability │ ├──entrybackupability │ │ └──EntryBackupAbility.ets // Data backup and restoration │ └──pages │ └──Index.ets // App entry └──entry/src/main/resources // Static resources of the app ``` ## How to Implement * The switchover between the foreground and background of an application is monitored using the [ApplicationContext.on('applicationStateChange')](https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-inner-application-applicationcontext-V5#applicationcontextonapplicationstatechange10) method. * The UIAbility is closed using the [UIAbilityContext.terminateSelf()](https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-inner-application-uiabilitycontext-V5#uiabilitycontextterminateself) method. * The application is closed using the [ApplicationContext.killAllProcesses()](https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-inner-application-applicationcontext-V5#applicationcontextkillallprocesses) method. * The application is restarted using the [ApplicationContext.restartApp()](https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-inner-application-applicationcontext-V5#applicationcontextrestartapp12) method. * The application is switched to the background using the [minimize()](https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-window-V5#minimize11) method of the **Window** module. ## Permissions N/A ## Dependencies N/A ## Constraints 1. The sample is only supported on Huawei phones with standard systems. 2. The HarmonyOS version must be HarmonyOS 5.0.0 Release or later. 3. The DevEco Studio version must be DevEco Studio 5.0.0 Release or later. 4. The HarmonyOS SDK version must be HarmonyOS 5.0.0 Release SDK or later.