1e41f4b71Sopenharmony_ci# @ohos.application.appManager (appManager) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **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. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.appManager](js-apis-app-ability-appManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.application.appManager (appManager)](js-apis-app-ability-wantConstant.md). 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport appManager from '@ohos.application.appManager'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## appManager.registerApplicationStateObserver 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciregisterApplicationStateObserver(observer: ApplicationStateObserver): number 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciRegisters an observer to listen for the state changes of all applications. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**System API**: This is a system API. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Parameters** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 32e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 33e41f4b71Sopenharmony_ci| observer | [ApplicationStateObserver (System API)](js-apis-inner-application-applicationStateObserver-sys.md)| Yes| Application state observer, which is used to observe the lifecycle change of an application.| 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**Return value** 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci| Type| Description| 38e41f4b71Sopenharmony_ci| --- | --- | 39e41f4b71Sopenharmony_ci| number | Digital code of the observer.| 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**Example** 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci ```ts 44e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci const observerCode = appManager.registerApplicationStateObserver({ 47e41f4b71Sopenharmony_ci onForegroundApplicationChanged(appStateData) { 48e41f4b71Sopenharmony_ci console.log('------------ onForegroundApplicationChanged -----------', appStateData); 49e41f4b71Sopenharmony_ci }, 50e41f4b71Sopenharmony_ci onAbilityStateChanged(abilityStateData) { 51e41f4b71Sopenharmony_ci console.log('------------ onAbilityStateChanged -----------', abilityStateData); 52e41f4b71Sopenharmony_ci }, 53e41f4b71Sopenharmony_ci onProcessCreated(processData) { 54e41f4b71Sopenharmony_ci console.log('------------ onProcessCreated -----------', processData); 55e41f4b71Sopenharmony_ci }, 56e41f4b71Sopenharmony_ci onProcessDied(processData) { 57e41f4b71Sopenharmony_ci console.log('------------ onProcessDied -----------', processData); 58e41f4b71Sopenharmony_ci }, 59e41f4b71Sopenharmony_ci onProcessStateChanged(processData) { 60e41f4b71Sopenharmony_ci console.log('------------ onProcessStateChanged -----------', processData); 61e41f4b71Sopenharmony_ci } 62e41f4b71Sopenharmony_ci }); 63e41f4b71Sopenharmony_ci console.log('-------- observerCode: ---------', observerCode); 64e41f4b71Sopenharmony_ci ``` 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci## appManager.unregisterApplicationStateObserver 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ciunregisterApplicationStateObserver(observerId: number, callback: AsyncCallback\<void>): void 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ciDeregisters the application state observer. This API uses an asynchronous callback to return the result. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**System API**: This is a system API. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**Parameters** 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 81e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 82e41f4b71Sopenharmony_ci| observerId | number | Yes| Numeric code of the observer.| 83e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**Example** 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci ```ts 88e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 89e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci let observerId = 100; 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci function unregisterApplicationStateObserverCallback(err: BusinessError) { 94e41f4b71Sopenharmony_ci if (err) { 95e41f4b71Sopenharmony_ci console.error('------------ unregisterApplicationStateObserverCallback ------------', err); 96e41f4b71Sopenharmony_ci } 97e41f4b71Sopenharmony_ci } 98e41f4b71Sopenharmony_ci appManager.unregisterApplicationStateObserver(observerId, unregisterApplicationStateObserverCallback); 99e41f4b71Sopenharmony_ci ``` 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci## appManager.unregisterApplicationStateObserver 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ciunregisterApplicationStateObserver(observerId: number): Promise\<void> 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ciDeregisters the application state observer. This API uses a promise to return the result. 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci**System API**: This is a system API. 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**Parameters** 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 116e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 117e41f4b71Sopenharmony_ci| observerId | number | Yes| Numeric code of the observer.| 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**Return value** 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci| Type| Description| 122e41f4b71Sopenharmony_ci| -------- | -------- | 123e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci**Example** 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci ```ts 128e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 129e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci let observerId = 100; 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci appManager.unregisterApplicationStateObserver(observerId) 134e41f4b71Sopenharmony_ci .then((data) => { 135e41f4b71Sopenharmony_ci console.log('----------- unregisterApplicationStateObserver success ----------', data); 136e41f4b71Sopenharmony_ci }) 137e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 138e41f4b71Sopenharmony_ci console.error('----------- unregisterApplicationStateObserver fail ----------', err); 139e41f4b71Sopenharmony_ci }); 140e41f4b71Sopenharmony_ci ``` 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci## appManager.getForegroundApplications 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_cigetForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ciObtains information about the applications that are running in the foreground. The application information is defined by [AppStateData](js-apis-inner-application-appStateData-sys.md). This API uses an asynchronous callback to return the result. 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**System API**: This is a system API. 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci**Parameters** 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 157e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 158e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData-sys.md)>> | Yes| Callback used to return the application information.| 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci**Example** 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci ```ts 163e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci appManager.getForegroundApplications((err, data) => { 166e41f4b71Sopenharmony_ci if (err) { 167e41f4b71Sopenharmony_ci console.error('--------- getForegroundApplicationsCallback fail ---------', err); 168e41f4b71Sopenharmony_ci } else { 169e41f4b71Sopenharmony_ci console.log('--------- getForegroundApplicationsCallback success ---------', data); 170e41f4b71Sopenharmony_ci } 171e41f4b71Sopenharmony_ci }); 172e41f4b71Sopenharmony_ci ``` 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci## appManager.getForegroundApplications 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_cigetForegroundApplications(): Promise\<Array\<AppStateData>> 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ciObtains information about the applications that are running in the foreground. The application information is defined by [AppStateData](js-apis-inner-application-appStateData-sys.md). This API uses a promise to return the result. 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**System API**: This is a system API. 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci**Return value** 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci| Type| Description| 189e41f4b71Sopenharmony_ci| -------- | -------- | 190e41f4b71Sopenharmony_ci| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData-sys.md)>> | Promise used to return the application information.| 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**Example** 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci ```ts 195e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 196e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci appManager.getForegroundApplications() 199e41f4b71Sopenharmony_ci .then((data) => { 200e41f4b71Sopenharmony_ci console.log('--------- getForegroundApplications success -------', data); 201e41f4b71Sopenharmony_ci }) 202e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 203e41f4b71Sopenharmony_ci console.error('--------- getForegroundApplications fail -------', err); 204e41f4b71Sopenharmony_ci }); 205e41f4b71Sopenharmony_ci ``` 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci## appManager.killProcessWithAccount 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_cikillProcessWithAccount(bundleName: string, accountId: number): Promise\<void\> 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ciKills a process by bundle name and account ID. This API uses a promise to return the result. 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci> **NOTE** 214e41f4b71Sopenharmony_ci> 215e41f4b71Sopenharmony_ci> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci**System API**: This is a system API. 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**Parameters** 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 226e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 227e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 228e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalidfromprocess).| 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci**Return value** 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci| Type| Description| 233e41f4b71Sopenharmony_ci| -------- | -------- | 234e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci**Example** 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci```ts 239e41f4b71Sopenharmony_ciimport appManager from '@ohos.application.appManager'; 240e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 243e41f4b71Sopenharmony_cilet accountId = 0; 244e41f4b71Sopenharmony_ciappManager.killProcessWithAccount(bundleName, accountId) 245e41f4b71Sopenharmony_ci .then((data) => { 246e41f4b71Sopenharmony_ci console.log('------------ killProcessWithAccount success ------------', data); 247e41f4b71Sopenharmony_ci }) 248e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 249e41f4b71Sopenharmony_ci console.error('------------ killProcessWithAccount fail ------------', err); 250e41f4b71Sopenharmony_ci }); 251e41f4b71Sopenharmony_ci``` 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci## appManager.killProcessWithAccount 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_cikillProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ciKills a process by bundle name and account ID. This API uses an asynchronous callback to return the result. 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci> **NOTE** 261e41f4b71Sopenharmony_ci> 262e41f4b71Sopenharmony_ci> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci**System API**: This is a system API. 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci**Parameters** 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 273e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 274e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 275e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalidfromprocess).| 276e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes| Callback used to return the result. If the process is killed, **err** is **undefined**; otherwise, **err** is an error object.| 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci**Example** 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci```ts 281e41f4b71Sopenharmony_ciimport appManager from '@ohos.application.appManager'; 282e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 285e41f4b71Sopenharmony_cilet accountId = 0; 286e41f4b71Sopenharmony_cifunction killProcessWithAccountCallback(err: BusinessError, data: void) { 287e41f4b71Sopenharmony_ci if (err) { 288e41f4b71Sopenharmony_ci console.error('------------- killProcessWithAccountCallback fail, err: --------------', err); 289e41f4b71Sopenharmony_ci } else { 290e41f4b71Sopenharmony_ci console.log('------------- killProcessWithAccountCallback success, data: --------------', data); 291e41f4b71Sopenharmony_ci } 292e41f4b71Sopenharmony_ci} 293e41f4b71Sopenharmony_ciappManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); 294e41f4b71Sopenharmony_ci``` 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci## appManager.killProcessesByBundleName 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_cikillProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>) 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ciKills a process by bundle name. This API uses an asynchronous callback to return the result. 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**System API**: This is a system API. 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**Parameters** 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 311e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 312e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 313e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the process is killed, **err** is **undefined**; otherwise, **err** is an error object.| 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci**Example** 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci ```ts 318e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 319e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci let bundleName = 'bundleName'; 322e41f4b71Sopenharmony_ci function killProcessesByBundleNameCallback(err: BusinessError, data: void) { 323e41f4b71Sopenharmony_ci if (err) { 324e41f4b71Sopenharmony_ci console.error('------------- killProcessesByBundleNameCallback fail, err: --------------', err); 325e41f4b71Sopenharmony_ci } else { 326e41f4b71Sopenharmony_ci console.log('------------- killProcessesByBundleNameCallback success, data: --------------', data); 327e41f4b71Sopenharmony_ci } 328e41f4b71Sopenharmony_ci } 329e41f4b71Sopenharmony_ci appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); 330e41f4b71Sopenharmony_ci ``` 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci## appManager.killProcessesByBundleName 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_cikillProcessesByBundleName(bundleName: string): Promise\<void> 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ciKills a process by bundle name. This API uses a promise to return the result. 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci**System API**: This is a system API. 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci**Parameters** 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 347e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 348e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci**Return value** 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci| Type| Description| 353e41f4b71Sopenharmony_ci| -------- | -------- | 354e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci**Example** 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci ```ts 359e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 360e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci let bundleName = 'com.example.myapplication'; 363e41f4b71Sopenharmony_ci appManager.killProcessesByBundleName(bundleName) 364e41f4b71Sopenharmony_ci .then((data) => { 365e41f4b71Sopenharmony_ci console.log('------------ killProcessesByBundleName success ------------', data); 366e41f4b71Sopenharmony_ci }) 367e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 368e41f4b71Sopenharmony_ci console.error('------------ killProcessesByBundleName fail ------------', err); 369e41f4b71Sopenharmony_ci }); 370e41f4b71Sopenharmony_ci ``` 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci## appManager.clearUpApplicationData 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ciclearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>) 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ciClears application data by bundle name. This API uses an asynchronous callback to return the result. 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci**System API**: This is a system API. 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci**Parameters** 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 387e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 388e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 389e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the application data is cleared, **err** is **undefined**; otherwise, **err** is an error object.| 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ci**Example** 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci ```ts 394e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 395e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci let bundleName = 'bundleName'; 398e41f4b71Sopenharmony_ci function clearUpApplicationDataCallback(err: BusinessError, data: void) { 399e41f4b71Sopenharmony_ci if (err) { 400e41f4b71Sopenharmony_ci console.error('------------- clearUpApplicationDataCallback fail, err: --------------', err); 401e41f4b71Sopenharmony_ci } else { 402e41f4b71Sopenharmony_ci console.log('------------- clearUpApplicationDataCallback success, data: --------------', data); 403e41f4b71Sopenharmony_ci } 404e41f4b71Sopenharmony_ci } 405e41f4b71Sopenharmony_ci appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); 406e41f4b71Sopenharmony_ci ``` 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci## appManager.clearUpApplicationData 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ciclearUpApplicationData(bundleName: string): Promise\<void> 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ciClears application data by bundle name. This API uses a promise to return the result. 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci**System API**: This is a system API. 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci**Parameters** 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 423e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 424e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci**Return value** 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci| Type| Description| 429e41f4b71Sopenharmony_ci| -------- | -------- | 430e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci**Example** 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci ```ts 435e41f4b71Sopenharmony_ci import appManager from '@ohos.application.appManager'; 436e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci let bundleName = 'bundleName'; 439e41f4b71Sopenharmony_ci appManager.clearUpApplicationData(bundleName) 440e41f4b71Sopenharmony_ci .then((data) => { 441e41f4b71Sopenharmony_ci console.log('------------ clearUpApplicationData success ------------', data); 442e41f4b71Sopenharmony_ci }) 443e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 444e41f4b71Sopenharmony_ci console.error('------------ clearUpApplicationData fail ------------', err); 445e41f4b71Sopenharmony_ci }); 446e41f4b71Sopenharmony_ci ``` 447