# @ohos.app.ability.appManager (appManager) (System API) The **appManager** module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory size of the application, and information about the running process. > **NOTE** > > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > > This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.app.ability.appManager (appManager)](js-apis-app-ability-appManager.md). ## Modules to Import ```ts import { appManager } from '@kit.AbilityKit'; ``` ## appManager.PreloadMode12+ Enumerates the modes used for preloading an application process. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Model restriction**: This API can be used only in the stage model. | Name | Value | Description | | ----------- | --- | --------------------------- | | PRESS_DOWN | 0 | The application process is preloaded when the application icon is pressed.| ## KeepAliveAppType14+ Enumerates the types of applications to be kept alive. **System API**: This is a system API. **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Value | Description| | -------- | ---------- | -------- | | ALL | 0 | Third-party and system applications. This value can be called only as an input parameter of [getKeepAliveBundles](#appmanagergetkeepalivebundles14). | | THIRD_PARTY | 1 | Third-party application. | | SYSTEM | 2 | System application.| ## KeepAliveSetter14+ Enumerates the types of parties that set to keep applications alive. **System API**: This is a system API. **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Value | Description| | -------- | ---------- | -------- | | SYSTEM | 0 | System, which means that the system sets to keep applications alive.| | USER | 1 | User, which means that a user sets to keep applications alive. | ## KeepAliveBundleInfo14+ Describes the keep-alive application information, which can be obtained by calling [getKeepAliveBundles](#appmanagergetkeepalivebundles14). **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. | Name| Type| Read-Only| Optional | Description| | ------------------------- | ------ | ---- | ---- | --------- | | bundleName | string | Yes| No | Bundle name.| | userId | number | Yes| No | User ID.| | appType | [KeepAliveAppType](#keepaliveapptype14) | Yes| No| Type of the application to be kept alive. | | setter | [KeepAliveSetter](#keepalivesetter14) | Yes| No| Type of the party that sets to keep the application alive. | ## appManager.isSharedBundleRunning10+ isSharedBundleRunning(bundleName: string, versionCode: number): Promise\ Checks whether the shared library is in use. This API uses a promise to return the result. **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | --------- | ---------------------------------------- | ---- | -------------- | | bundleName | string | Yes | Bundle name of the shared library.| | versionCode | number | Yes | Version number of the shared library. | **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; const bundleName = "this is a bundleName"; const versionCode = 1; appManager.isSharedBundleRunning(bundleName, versionCode).then((data) => { console.log(`The shared bundle running is: ${JSON.stringify(data)}`); }).catch((error: BusinessError) => { console.error(`error: ${JSON.stringify(error)}`); }); ``` ## appManager.isSharedBundleRunning10+ isSharedBundleRunning(bundleName: string, versionCode: number, callback: AsyncCallback\): void Checks whether the shared library is in use. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | --------- | ---------------------------------------- | ---- | -------------- | | bundleName | string | Yes | Bundle name of the shared library.| | versionCode | number | Yes | Version number of the shared library. | | callback | AsyncCallback\> | Yes | Callback used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; const bundleName = "this is a bundleName"; const versionCode = 1; appManager.isSharedBundleRunning(bundleName, versionCode, (err, data) => { if (err) { console.error(`err: ${JSON.stringify(err)}`); } else { console.log(`The shared bundle running is: ${JSON.stringify(data)}`); } }); ``` ## appManager.on('appForegroundState')11+ on(type: 'appForegroundState', observer: AppForegroundStateObserver): void Registers an observer to listen for application start or exit events. The observer can be used by a system application to observe the start or event events of all applications. **System API**: This is a system API. **Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. It is fixed at **'appForegroundState'**.| | observer | [AppForegroundStateObserver](js-apis-inner-application-appForegroundStateObserver-sys.md) | Yes| Observer used to listen for application start or exit events.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let observer: appManager.AppForegroundStateObserver = { onAppStateChanged(appStateData) { console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`); }, }; try { appManager.on('appForegroundState', observer); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.on('abilityFirstFrameState')12+ on(type: 'abilityFirstFrameState', observer: AbilityFirstFrameStateObserver, bundleName?: string): void Registers an observer to listen for the complete of the first frame rendering of a given ability. **System API**: This is a system API. **Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. It is fixed at **'abilityFirstFrameState'**. | | observer | [AbilityFirstFrameStateObserver](js-apis-inner-application-abilityFirstFrameStateObserver-sys.md) | Yes | Observer used to listen for the complete of the first frame rendering of the ability. | | bundleName | string | No | Bundle name of the ability to be listened for. If this parameter is left blank, the event is listened for all applications.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = { onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) { console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData)); } }; try { appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); } catch (e) { let code = (e as BusinessError).code; let message = (e as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.off('applicationState') off(type: 'applicationState', observerId: number, callback: AsyncCallback\): void Deregisters the application state observer. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| | observerId | number | Yes| Digital code of the observer.| | callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let observerId = 0; let applicationStateObserver: appManager.ApplicationStateObserver = { onForegroundApplicationChanged(appStateData) { console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); }, onAbilityStateChanged(abilityStateData) { console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); }, onProcessCreated(processData) { console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); }, onProcessDied(processData) { console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); }, onProcessStateChanged(processData) { console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); }, onAppStarted(appStateData) { console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); }, onAppStopped(appStateData) { console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); } }; let bundleNameList = ['bundleName1', 'bundleName2']; try { observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); console.log(`[appManager] observerCode: ${observerId}`); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message} `); } // 2. Deregister the application state observer. function unregisterApplicationStateObserverCallback(err: BusinessError) { if (err) { console.error(`unregisterApplicationStateObserverCallback fail, err: ${JSON.stringify(err)}`); } else { console.log('unregisterApplicationStateObserverCallback success.'); } } try { appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.off('appForegroundState')11+ off(type: 'appForegroundState', observer?: AppForegroundStateObserver): void Deregisters the observer used to listen for application start or exit events. **System API**: This is a system API. **Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | string | Yes| Event type. It is fixed at **'appForegroundState'**.| | observer | [AppForegroundStateObserver](js-apis-inner-application-appForegroundStateObserver-sys.md) | No| Observer used to listen for application start or exit events.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let observer_: appManager.AppForegroundStateObserver | undefined; // 1. Register an observer to listen for application start or exit events. let observer: appManager.AppForegroundStateObserver = { onAppStateChanged(appStateData: appManager.AppStateData) { console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`); }, }; try { appManager.on('appForegroundState', observer); // Save the observer object. observer_ = observer; } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } // 2. Deregister the observer. try { appManager.off('appForegroundState', observer_); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.off('abilityFirstFrameState')12+ off(type: 'abilityFirstFrameState', observer?: AbilityFirstFrameStateObserver): void Deregisters the observer used to listen for the complete of the first frame rendering of a given ability. **System API**: This is a system API. **Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. It is fixed at **'abilityFirstFrameState'**. | | observer | [AbilityFirstFrameStateObserver](js-apis-inner-application-abilityFirstFrameStateObserver-sys.md) | No | Callback used for deregistration. If this parameter is left blank, all subscriptions to the specified event are canceled.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = { onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) { console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData)); } }; try { appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); } catch (e) { let code = (e as BusinessError).code; let message = (e as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } try { appManager.off('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); } catch (e) { let code = (e as BusinessError).code; let message = (e as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.getForegroundApplications getForegroundApplications(callback: AsyncCallback\>): void Obtains applications that are running in the foreground. This API uses an asynchronous callback to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData.md). **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback\> | Yes| Callback used to return the API call result and an array holding the application state data. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; function getForegroundApplicationsCallback(err: BusinessError, data: Array) { if (err) { console.error(`getForegroundApplicationsCallback fail, err: ${JSON.stringify(err)}`); } else { console.log(`getForegroundApplicationsCallback success, data: ${JSON.stringify(data)}`); } } try { appManager.getForegroundApplications(getForegroundApplicationsCallback); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.getForegroundApplications getForegroundApplications(): Promise\> Obtains applications that are running in the foreground. This API uses a promise to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData.md). **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Return value** | Type| Description| | -------- | -------- | | Promise\> | Promise used to return an array holding the application state data.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; appManager.getForegroundApplications().then((data) => { console.log(`getForegroundApplications success, data: ${JSON.stringify(data)}`); }).catch((err: BusinessError) => { console.error(`getForegroundApplications fail, err: ${JSON.stringify(err)}`); }); ``` ## appManager.killProcessWithAccount killProcessWithAccount(bundleName: string, accountId: number): Promise\ Kills a process by bundle name and account ID. This API uses a promise to return the result. > **NOTE** > > The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. **Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES, or ohos.permission.CLEAN_BACKGROUND_PROCESSES **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| **Return value** | Type | Description | | -------------- | --------------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = 'bundleName'; let accountId = 0; try { appManager.killProcessWithAccount(bundleName, accountId).then(() => { console.log('killProcessWithAccount success'); }).catch((err: BusinessError) => { console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.killProcessWithAccount14+ killProcessWithAccount(bundleName: string, accountId: number, clearPageStack: boolean, appIndex?: number): Promise\ Kills a process by bundle name and account ID. This API uses a promise to return the result. > **NOTE** > > The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. **Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| | clearPageStack | boolean | Yes| Whether to clear the page stack. The value **true** means to clear the page stack, and **false** means the opposite.| | appIndex | number | No| Index of an application clone.| **Return value** | Type | Description | | -------------- | --------------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = 'bundleName'; let accountId = 0; let isClearPageStack = false; let appIndex = 1; try { appManager.killProcessWithAccount(bundleName, accountId, isClearPageStack, appIndex).then(() => { console.log('killProcessWithAccount success'); }).catch((err: BusinessError) => { console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.killProcessWithAccount killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\): void Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result. > **NOTE** > > The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. **Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES, or ohos.permission.CLEAN_BACKGROUND_PROCESSES **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| | callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = 'bundleName'; let accountId = 0; function killProcessWithAccountCallback(err: BusinessError) { if (err) { console.error(`killProcessWithAccountCallback fail, err: ${JSON.stringify(err)}`); } else { console.log('killProcessWithAccountCallback success.'); } } appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); ``` ## appManager.killProcessesByBundleName killProcessesByBundleName(bundleName: string, callback: AsyncCallback\) Kills a process by bundle name. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = 'bundleName'; function killProcessesByBundleNameCallback(err: BusinessError) { if (err) { console.error(`killProcessesByBundleNameCallback fail, err: ${JSON.stringify(err)}`); } else { console.log('killProcessesByBundleNameCallback success.'); } } try { appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.killProcessesByBundleName killProcessesByBundleName(bundleName: string): Promise\ Kills a process by bundle name. This API uses a promise to return the result. **Required permissions**: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = 'bundleName'; try { appManager.killProcessesByBundleName(bundleName).then((data) => { console.log('killProcessesByBundleName success.'); }).catch((err: BusinessError) => { console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.clearUpApplicationData clearUpApplicationData(bundleName: string, callback: AsyncCallback\) Clears application data by bundle name. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = 'bundleName'; function clearUpApplicationDataCallback(err: BusinessError) { if (err) { console.error(`clearUpApplicationDataCallback fail, err: ${JSON.stringify(err)}`); } else { console.log('clearUpApplicationDataCallback success.'); } } try { appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.clearUpApplicationData clearUpApplicationData(bundleName: string): Promise\ Clears application data by bundle name. This API uses a promise to return the result. **Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = 'bundleName'; try { appManager.clearUpApplicationData(bundleName).then((data) => { console.log('clearUpApplicationData success.'); }).catch((err: BusinessError) => { console.error(`clearUpApplicationData fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.getProcessMemoryByPid10+ getProcessMemoryByPid(pid: number, callback: AsyncCallback\): void Obtains the memory size of a process. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](#appmanagergetrunningprocessinfobybundlename10).| | callback | AsyncCallback\ | Yes| Callback used to return the API call result and the memory size (in KB). You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let pid = 0; function getProcessMemoryByPidCallback(err: BusinessError, data: number) { if (err) { console.error(`getProcessMemoryByPidCallback fail, err: ${JSON.stringify(err)}`); } else { console.log('getProcessMemoryByPidCallback success.'); } } try { appManager.getProcessMemoryByPid(pid, getProcessMemoryByPidCallback); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.getProcessMemoryByPid10+ getProcessMemoryByPid(pid: number): Promise\ Obtains the memory size of a process. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](#appmanagergetrunningprocessinfobybundlename10). | **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise used to return the API call result and the memory size (in KB). You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let pid = 0; try { appManager.getProcessMemoryByPid(pid).then((data) => { console.log('getProcessMemoryByPid success.'); }).catch((err: BusinessError) => { console.error(`getProcessMemoryByPid fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.getRunningProcessInfoByBundleName10+ getRunningProcessInfoByBundleName(bundleName: string, callback: AsyncCallback\>): void Obtains information about the running processes by bundle name. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | callback | AsyncCallback\> | Yes| Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = "bundleName"; function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array) { if (err) { console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`); } else { console.log('getRunningProcessInfoByBundleNameCallback success.'); } } try { appManager.getRunningProcessInfoByBundleName(bundleName, getRunningProcessInfoByBundleNameCallback); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.getRunningProcessInfoByBundleName10+ getRunningProcessInfoByBundleName(bundleName: string): Promise\> Obtains information about the running processes by bundle name. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| **Return value** | Type| Description| | -------- | -------- | | Promise\> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = "bundleName"; try { appManager.getRunningProcessInfoByBundleName(bundleName).then((data) => { console.log('getRunningProcessInfoByBundleName success.'); }).catch((err: BusinessError) => { console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.getRunningProcessInfoByBundleName10+ getRunningProcessInfoByBundleName(bundleName: string, userId: number, callback: AsyncCallback\>): void Obtains information about the running processes by bundle name and user ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | userId | number | Yes| User ID.| | callback | AsyncCallback\> | Yes| Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = "bundleName"; let userId = 0; function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array) { if (err) { console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`); } else { console.log('getRunningProcessInfoByBundleNameCallback success.'); } } try { appManager.getRunningProcessInfoByBundleName(bundleName, userId, getRunningProcessInfoByBundleNameCallback); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.getRunningProcessInfoByBundleName10+ getRunningProcessInfoByBundleName(bundleName: string, userId: number): Promise\> Obtains information about the running processes by bundle name and user ID. This API uses a promise to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | userId | number | Yes| User ID.| **Return value** | Type| Description| | -------- | -------- | | Promise\> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = "bundleName"; let userId = 0; try { appManager.getRunningProcessInfoByBundleName(bundleName, userId).then((data) => { console.log('getRunningProcessInfoByBundleName success.'); }).catch((err: BusinessError) => { console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.isApplicationRunning11+ isApplicationRunning(bundleName: string): Promise\ Checks whether an application is running. This API uses a promise to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory | Description | | --------- | ---------------------------------------- | ---- | -------------- | | bundleName | string | Yes | Bundle name.| **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise used to return the result. The value **true** means that the application is running, and **false** means the opposite.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = "com.example.myapplication"; appManager.isApplicationRunning(bundleName).then((data) => { console.log(`The application running is: ${JSON.stringify(data)}`); }).catch((error: BusinessError) => { console.error(`error: ${JSON.stringify(error)}`); }); ``` ## appManager.isApplicationRunning11+ isApplicationRunning(bundleName: string, callback: AsyncCallback\): void Checks whether an application is running. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory | Description | | --------- | ---------------------------------------- | ---- | -------------- | | bundleName | string | Yes | Bundle name of the shared library.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. The value **true** means that the application is running, and **false** means the opposite.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName = "com.example.myapplication"; try { appManager.isApplicationRunning(bundleName, (err, data) => { if (err) { console.error(`err: ${JSON.stringify(err)}`); } else { console.log(`The application running is: ${JSON.stringify(data)}`); } }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## ApplicationState Enumerates the application states. This enum can be used together with [AbilityStateData](js-apis-inner-application-abilityStateData.md) to return the application state. **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. | Name | Value | Description | | -------------------- | --- | --------------------------------- | | STATE_CREATE | 0 | The application is being created. | | STATE_FOREGROUND | 2 | The application is running in the foreground. | | STATE_ACTIVE | 3 | The application is active. | | STATE_BACKGROUND | 4 | The application is running in the background. | | STATE_DESTROY | 5 | The application is being destroyed. | ## appManager.getRunningProcessInformationByBundleType12+ getRunningProcessInformationByBundleType(bundleType: bundleManager.BundleType): Promise\> Obtains the information about the running process based on the bundle type. This API uses a promise to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** | Name | Type | Mandatory | Description | | --------- | ---------------------------------------- | ---- | -------------- | | bundleType | [bundleManager.BundleType](js-apis-bundleManager.md#bundletype) | Yes | Bundle type.| **Return value** | Type| Description| | -------- | -------- | | Promise\> | Promise used to return the process information.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager, bundleManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; try { appManager.getRunningProcessInformationByBundleType(bundleManager.BundleType.ATOMIC_SERVICE) .then((data) => { console.log(`The running process information is: ${JSON.stringify(data)}`); }).catch((error: BusinessError) => { console.error(`error: ${JSON.stringify(error)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.preloadApplication12+ preloadApplication(bundleName: string, userId: number, mode: PreloadMode, appIndex?: number): Promise\ Preloads an application process. A successful call does not always mean that the preloading is successful. In other words, the target application process may not be created even if the API is successfully called. This API uses a promise to return the result. **Required permissions**: ohos.permission.PRELOAD_APPLICATION **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Model restriction**: This API can be used only in the stage model. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name of the application to preload.| | userId | number | Yes| User ID.| | mode | [PreloadMode](#appmanagerpreloadmode12) | Yes| Mode used for preloading.| | appIndex | number | No| Application index of the twin application to be preloaded.| **Return value** | Type | Description | | -------------- | ---------------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | The application does not have permission to call the interface. | | 202 | Not system application. | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16000050 | Internal error. | | 16300005 | The target bundle does not exist. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; try { let bundleName = "ohos.samples.etsclock"; let userId = 100; let mode = appManager.PreloadMode.PRESS_DOWN; let appIndex = 0; appManager.preloadApplication(bundleName, userId, mode, appIndex) .then(() => { hilog.info(0x0000, 'testTag', `preloadApplication success`); }) .catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${err.code}, msg:${err.message}`); }) } catch (err) { hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${(err as BusinessError).code}, msg:${(err as BusinessError).message}`); } ``` ## appManager.getRunningMultiAppInfo12+ getRunningMultiAppInfo(bundleName: string): Promise\ Obtains the information about running applications in multi-app mode. This API uses a promise to return the result. The multi-app mode means that an application can be simultaneously logged in with different accounts on the same device. **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Model restriction**: This API can be used only in the stage model. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| **Return value** | Type | Description | | -------------- | ---------------- | | Promise\<[RunningMultiAppInfo](js-apis-inner-application-runningMultiAppInfo-sys.md)> | Promise used to return the information about running applications with multi-app mode.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | The application does not have permission to call the interface. | | 202 | Not system application. | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16000072 | App clone or multi-instance is not supported. | | 18500001 | The bundle does not exist or no patch has been applied. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; try { let bundleName = "ohos.samples.etsclock"; appManager.getRunningMultiAppInfo(bundleName).then((info: appManager.RunningMultiAppInfo) => { hilog.info(0x0000, 'testTag', `getRunningMultiAppInfo success`); }).catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`); }) } catch (err) { hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`); } ``` ## appManager.terminateMission12+ terminateMission(missionId: number): Promise\ Terminates a mission. This API uses a promise to return the result. **Required permissions**: ohos.permission.KILL_APP_PROCESSES **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | missionId | number | Yes| Mission ID, which can be obtained by calling [getMissionInfos](js-apis-app-ability-missionManager-sys.md#missionmanagergetmissioninfos).| **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component struct Index { build() { Button('start link', { type: ButtonType.Capsule, stateEffect: true }) .width('87%') .height('5%') .margin({ bottom: '12vp' }) .onClick(() => { let missionId: number = 0; try { appManager.terminateMission(missionId).then(()=>{ console.log('terminateMission success.'); }).catch((err: BusinessError)=>{ console.error('terminateMission failed. err: ' + JSON.stringify(err)); }) } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } }) } } ``` ## appManager.getSupportedProcessCachePids14+ getSupportedProcessCachePids(bundleName : string): Promise\> Obtains the PIDs of processes that support quick startup after caching in a specified application. > **NOTE** > > This API can only be used to obtain the PIDs of the system account to which the caller belongs. **Required permissions**: ohos.permission.GET_RUNNING_INFO **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Model restriction**: This API can be used only in the stage model. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes | Bundle name.| **Return value** | Type| Description| | -------- | -------- | | Promise\> | Promise used to return an array containing the PIDs.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 801 | Capability not supported. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; try { let bundleName = "ohos.samples.processcache"; appManager.getSupportedProcessCachePids(bundleName).then((pids: Array) => { hilog.info(0x0000, 'testTag', `pids: ${JSON.stringify(pids)}`); }).catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`); }) } catch (err) { hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`); } ``` ## appManager.clearUpAppData13+ clearUpAppData(bundleName: string, appCloneIndex?: number): Promise\ Clears data of a specified application based on the bundle name and application clone index. **Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Bundle name.| | appCloneIndex | number | No| Index of the application clone.| **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 16000050 | Internal error. | | 16000073 | The app clone index does not exist. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let bundleName: string = 'com.ohos.demo'; let appCloneIndex: number = 0; try { appManager.clearUpAppData(bundleName, appCloneIndex).then(() => { console.log(`clearUpAppData success.`); }).catch((err: BusinessError) => { console.error(`clearUpAppData fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] error: ${code}, ${message}`); } ``` ## appManager.setKeepAliveForBundle14+ setKeepAliveForBundle(bundleName: string, userId: number, enable: boolean): Promise\ Keeps an application of a specified user alive, or cancels its keep-alive status. This API uses a promise to return the result. Currently, this API takes effect only on 2-in-1 devices. **Permission required**: ohos.permission.MANAGE_APP_KEEP_ALIVE **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes | Bundle name.| | userId | number | Yes | User ID.| | enable | boolean | Yes | Whether to keep the application alive or cancel its keep-alive status.| **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 801 | Capability not supported. | | 16000050 | Internal error. | | 16300005 | The target bundle does not exist. | | 16300008 | The target bundle has no main ability. | | 16300009 | The target bundle has no status-bar ability. | | 16300010 | The target application is not attached to status bar. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; try { let bundleName = "ohos.samples.keepaliveapp"; let userId = 100; appManager.setKeepAliveForBundle(bundleName, userId, true).then(() => { console.log(`setKeepAliveForBundle success`); }).catch((err: BusinessError) => { console.error(`setKeepAliveForBundle fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] setKeepAliveForBundle error: ${code}, ${message}`); } ``` ## appManager.getKeepAliveBundles14+ getKeepAliveBundles(type: KeepAliveAppType, userId?: number): Promise\> Obtains information about a specified type of keep-alive application of a user. The application information is defined by [KeepAliveBundleInfo](#keepalivebundleinfo14). This API uses a promise to return the result. Currently, this API takes effect only on 2-in-1 devices. **Permission required**: ohos.permission.MANAGE_APP_KEEP_ALIVE **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | [KeepAliveAppType](#keepaliveapptype14) | Yes | Type of the application.| | userId | number | No | User ID.| **Return value** | Type| Description| | -------- | -------- | | Promise\> | Promise used to return the array of keep-alive application information.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 801 | Capability not supported. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let userId = 100; let type: appManager.KeepAliveAppType = appManager.KeepAliveAppType.THIRD_PARTY; try { appManager.getKeepAliveBundles(type, userId).then((data) => { console.log(`getKeepAliveBundles success, data: ${JSON.stringify(data)}`); }).catch((err: BusinessError) => { console.error(`getKeepAliveBundles fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] getKeepAliveBundles error: ${code}, ${message}`); } ``` ## appManager.killProcessesInBatch14+ killProcessesInBatch(pids: Array\): Promise\ Kill processes in batches. Currently, this API takes effect only on 2-in-1 devices. **Required permissions**: ohos.permission.KILL_APP_PROCESSES **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | pids | Array\ | Yes | IDs of the processes to kill.| **Return value** | Type| Description| | -------- | -------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). | ID| Error Message| | ------- | -------- | | 201 | Permission denied. | | 202 | Not System App. Interface caller is not a system app. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 801 | Capability not supported. | | 16000050 | Internal error. | **Example** ```ts import { appManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; try { let pids: Array = [100, 101, 102]; appManager.killProcessesInBatch(pids).then(() => { console.log(`killProcessesInBatch success`); }).catch((err: BusinessError) => { console.error(`killProcessesInBatch fail, err: ${JSON.stringify(err)}`); }); } catch (paramError) { let code = (paramError as BusinessError).code; let message = (paramError as BusinessError).message; console.error(`[appManager] killProcessesInBatch error: ${code}, ${message}`); } ```