1# @ohos.application.appManager (appManager) 2 3The **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. 4 5> **NOTE** 6> 7> The APIs of this module are supported since API version 7 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. 8 9## Modules to Import 10 11```ts 12import app from '@ohos.application.appManager'; 13``` 14 15## appManager.isRunningInStabilityTest<sup>8+</sup> 16 17static isRunningInStabilityTest(callback: AsyncCallback<boolean>): void 18 19Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result. 20 21**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22 23**Parameters** 24 25 | Name| Type| Mandatory| Description| 26 | -------- | -------- | -------- | -------- | 27 | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| 28 29**Example** 30 31 ```ts 32 import app from '@ohos.application.appManager'; 33 app.isRunningInStabilityTest((err, flag) => { 34 console.log('startAbility result:' + JSON.stringify(err)); 35 }); 36 ``` 37 38 39## appManager.isRunningInStabilityTest<sup>8+</sup> 40 41static isRunningInStabilityTest(): Promise<boolean> 42 43Checks whether this application is undergoing a stability test. This API uses a promise to return the result. 44 45**System capability**: SystemCapability.Ability.AbilityRuntime.Core 46 47**Return value** 48 49 | Type| Description| 50 | -------- | -------- | 51 | Promise<boolean> | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| 52 53**Example** 54 55 ```ts 56 import app from '@ohos.application.appManager'; 57 app.isRunningInStabilityTest().then((flag) => { 58 console.log('success:' + JSON.stringify(flag)); 59 }).catch((error) => { 60 console.log('failed:' + JSON.stringify(error)); 61 }); 62 ``` 63 64 65## appManager.isRamConstrainedDevice 66 67isRamConstrainedDevice(): Promise\<boolean>; 68 69Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result. 70 71**System capability**: SystemCapability.Ability.AbilityRuntime.Core 72 73**Return value** 74 75 | Type| Description| 76 | -------- | -------- | 77 | Promise<boolean> | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| 78 79**Example** 80 81 ```ts 82 app.isRamConstrainedDevice().then((data) => { 83 console.log('success:' + JSON.stringify(data)); 84 }).catch((error) => { 85 console.log('failed:' + JSON.stringify(error)); 86 }); 87 ``` 88 89## appManager.isRamConstrainedDevice 90 91isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void; 92 93Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result. 94 95**System capability**: SystemCapability.Ability.AbilityRuntime.Core 96 97**Parameters** 98 99 | Name| Type| Mandatory| Description| 100 | -------- | -------- | -------- | -------- | 101 | callback | AsyncCallback<boolean> | Yes| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| 102 103**Example** 104 105 ```ts 106 app.isRamConstrainedDevice((err, data) => { 107 console.log('startAbility result failed:' + JSON.stringify(err)); 108 console.log('startAbility result success:' + JSON.stringify(data)); 109 }); 110 ``` 111 112## appManager.getAppMemorySize 113 114getAppMemorySize(): Promise\<number>; 115 116Obtains the memory size of this application. This API uses a promise to return the result. 117 118**System capability**: SystemCapability.Ability.AbilityRuntime.Core 119 120**Return value** 121 122 | Type| Description| 123 | -------- | -------- | 124 | Promise<number> | Promise used to return the memory size, in MB.| 125 126**Example** 127 128 ```ts 129 app.getAppMemorySize().then((data) => { 130 console.log('success:' + JSON.stringify(data)); 131 }).catch((error) => { 132 console.log('failed:' + JSON.stringify(error)); 133 }); 134 ``` 135 136## appManager.getAppMemorySize 137 138getAppMemorySize(callback: AsyncCallback\<number>): void; 139 140Obtains the memory size of this application. This API uses an asynchronous callback to return the result. 141 142**System capability**: SystemCapability.Ability.AbilityRuntime.Core 143 144**Parameters** 145 146 | Name| Type| Mandatory| Description| 147 | -------- | -------- | -------- | -------- | 148 | callback | AsyncCallback<number> | Yes| Callback used to return the memory size, in MB.| 149 150**Example** 151 152 ```ts 153 app.getAppMemorySize((err, data) => { 154 console.log('startAbility result failed :' + JSON.stringify(err)); 155 console.log('startAbility result success:' + JSON.stringify(data)); 156 }); 157 ``` 158## appManager.getProcessRunningInfos<sup>(deprecated)</sup> 159 160getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>; 161 162Obtains information about the running processes. This API uses a promise to return the result. 163 164> This API is deprecated since API version 9. You are advised to use [appManager.getRunningProcessInformation<sup>9+</sup>](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation) instead. 165 166**Required permissions**: ohos.permission.GET_RUNNING_INFO 167 168**System capability**: SystemCapability.Ability.AbilityRuntime.Core 169 170**Return value** 171 172| Type| Description| 173| -------- | -------- | 174| Promise\<Array\<[ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)>> | Promise used to return the process information.| 175 176**Example** 177 178 ```ts 179 app.getProcessRunningInfos().then((data) => { 180 console.log('success:' + JSON.stringify(data)); 181 }).catch((error) => { 182 console.log('failed:' + JSON.stringify(error)); 183 }); 184 ``` 185 186## appManager.getProcessRunningInfos<sup>(deprecated)</sup> 187 188getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void; 189 190Obtains information about the running processes. This API uses an asynchronous callback to return the result. 191 192> This API is deprecated since API version 9. You are advised to use [appManager.getRunningProcessInformation<sup>9+</sup>](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation9) instead. 193 194**Required permissions**: ohos.permission.GET_RUNNING_INFO 195 196**System capability**: SystemCapability.Ability.AbilityRuntime.Core 197 198**Parameters** 199 200| Name| Type| Mandatory| Description| 201| -------- | -------- | -------- | -------- | 202| callback | AsyncCallback\<Array\<[ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)>> | Yes| Callback used to return the running processes. | 203 204**Example** 205 206 ```ts 207 app.getProcessRunningInfos((err, data) => { 208 console.log('startAbility result failed :' + JSON.stringify(err)); 209 console.log('startAbility result success:' + JSON.stringify(data)); 210 }); 211 ``` 212 213## appManager.registerApplicationStateObserver<sup>8+</sup> 214 215registerApplicationStateObserver(observer: ApplicationStateObserver): number; 216 217Registers an observer to listen for the state changes of all applications. 218 219**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 220 221**System capability**: SystemCapability.Ability.AbilityRuntime.Core 222 223**System API**: This is a system API and cannot be called by third-party applications. 224 225**Parameters** 226 227| Name| Type| Mandatory| Description| 228| -------- | -------- | -------- | -------- | 229| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) | Yes| Numeric code of the observer.| 230 231**Example** 232 233 ```ts 234 let applicationStateObserver = { 235 onForegroundApplicationChanged(appStateData) { 236 console.log('------------ onForegroundApplicationChanged -----------', appStateData); 237 }, 238 onAbilityStateChanged(abilityStateData) { 239 console.log('------------ onAbilityStateChanged -----------', abilityStateData); 240 }, 241 onProcessCreated(processData) { 242 console.log('------------ onProcessCreated -----------', processData); 243 }, 244 onProcessDied(processData) { 245 console.log('------------ onProcessDied -----------', processData); 246 }, 247 onProcessStateChanged(processData) { 248 console.log('------------ onProcessStateChanged -----------', processData); 249 } 250 }; 251 const observerCode = app.registerApplicationStateObserver(applicationStateObserver); 252 console.log('-------- observerCode: ---------', observerCode); 253 ``` 254 255## appManager.unregisterApplicationStateObserver<sup>8+</sup> 256 257unregisterApplicationStateObserver(observerId: number, callback: AsyncCallback\<void>): void; 258 259Deregisters the application state observer. This API uses an asynchronous callback to return the result. 260 261**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 262 263**System capability**: SystemCapability.Ability.AbilityRuntime.Core 264 265**System API**: This is a system API and cannot be called by third-party applications. 266 267**Parameters** 268 269| Name| Type| Mandatory| Description| 270| -------- | -------- | -------- | -------- | 271| observerId | number | Yes| Numeric code of the observer.| 272| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 273 274**Example** 275 276 ```ts 277 let observerId = 100; 278 279 function unregisterApplicationStateObserverCallback(err) { 280 if (err) { 281 console.log('------------ unregisterApplicationStateObserverCallback ------------', err); 282 } 283 } 284 app.unregisterApplicationStateObserver(observerId, unregisterApplicationStateObserverCallback); 285 ``` 286 287## appManager.unregisterApplicationStateObserver<sup>8+</sup> 288 289unregisterApplicationStateObserver(observerId: number): Promise\<void>; 290 291Deregisters the application state observer. This API uses a promise to return the result. 292 293**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 294 295**System capability**: SystemCapability.Ability.AbilityRuntime.Core 296 297**System API**: This is a system API and cannot be called by third-party applications. 298 299**Parameters** 300 301| Name| Type| Mandatory| Description| 302| -------- | -------- | -------- | -------- | 303| observerId | number | Yes| Numeric code of the observer.| 304 305**Return value** 306 307| Type| Description| 308| -------- | -------- | 309| Promise\<void> | Promise used to return the result.| 310 311**Example** 312 313 ```ts 314 let observerId = 100; 315 316 app.unregisterApplicationStateObserver(observerId) 317 .then((data) => { 318 console.log('----------- unregisterApplicationStateObserver success ----------', data); 319 }) 320 .catch((err) => { 321 console.log('----------- unregisterApplicationStateObserver fail ----------', err); 322 }); 323 ``` 324 325## appManager.getForegroundApplications<sup>8+</sup> 326 327getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void; 328 329Obtains information about the 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). 330 331**Required permissions**: ohos.permission.GET_RUNNING_INFO 332 333**System capability**: SystemCapability.Ability.AbilityRuntime.Core 334 335**System API**: This is a system API and cannot be called by third-party applications. 336 337**Parameters** 338 339| Name| Type| Mandatory| Description| 340| -------- | -------- | -------- | -------- | 341| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Yes| Callback used to return the application information.| 342 343**Example** 344 345 ```ts 346 function getForegroundApplicationsCallback(err, data) { 347 if (err) { 348 console.log('--------- getForegroundApplicationsCallback fail ---------', err); 349 } else { 350 console.log('--------- getForegroundApplicationsCallback success ---------', data) 351 } 352 } 353 app.getForegroundApplications(getForegroundApplicationsCallback); 354 ``` 355 356## appManager.getForegroundApplications<sup>8+</sup> 357 358getForegroundApplications(): Promise\<Array\<AppStateData>>; 359 360Obtains information about the 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). 361 362**Required permissions**: ohos.permission.GET_RUNNING_INFO 363 364**System capability**: SystemCapability.Ability.AbilityRuntime.Core 365 366**System API**: This is a system API and cannot be called by third-party applications. 367 368**Return value** 369 370| Type| Description| 371| -------- | -------- | 372| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Promise used to return the application information.| 373 374**Example** 375 376 ```ts 377 app.getForegroundApplications() 378 .then((data) => { 379 console.log('--------- getForegroundApplications success -------', data); 380 }) 381 .catch((err) => { 382 console.log('--------- getForegroundApplications fail -------', err); 383 }); 384 ``` 385 386## appManager.killProcessWithAccount<sup>8+</sup> 387 388killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\> 389 390Kills a process by bundle name and account ID. This API uses a promise to return the result. 391 392> **NOTE** 393> 394> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 395 396**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 397 398**System capability**: SystemCapability.Ability.AbilityRuntime.Core 399 400**System API**: This is a system API and cannot be called by third-party applications. 401 402**Parameters** 403 404 | Name| Type| Mandatory| Description| 405 | -------- | -------- | -------- | -------- | 406 | bundleName | string | Yes| Bundle name.| 407 | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).| 408 409**Example** 410 411```ts 412let bundleName = 'bundleName'; 413let accountId = 0; 414app.killProcessWithAccount(bundleName, accountId) 415 .then((data) => { 416 console.log('------------ killProcessWithAccount success ------------', data); 417 }) 418 .catch((err) => { 419 console.log('------------ killProcessWithAccount fail ------------', err); 420 }); 421``` 422 423 424## appManager.killProcessWithAccount<sup>8+</sup> 425 426killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void 427 428Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result. 429 430> **NOTE** 431> 432> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 433 434**System capability**: SystemCapability.Ability.AbilityRuntime.Core 435 436**System API**: This is a system API and cannot be called by third-party applications. 437 438**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 439 440**Parameters** 441 442 | Name| Type| Mandatory| Description| 443 | -------- | -------- | -------- | -------- | 444 | bundleName | string | Yes| Bundle name.| 445 | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).| 446 | callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 447 448**Example** 449 450```ts 451let bundleName = 'bundleName'; 452let accountId = 0; 453function killProcessWithAccountCallback(err, data) { 454 if (err) { 455 console.log('------------- killProcessWithAccountCallback fail, err: --------------', err); 456 } else { 457 console.log('------------- killProcessWithAccountCallback success, data: --------------', data); 458 } 459} 460app.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); 461``` 462 463## appManager.killProcessesByBundleName<sup>8+</sup> 464 465killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>); 466 467Kills a process by bundle name. This API uses an asynchronous callback to return the result. 468 469**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 470 471**System capability**: SystemCapability.Ability.AbilityRuntime.Core 472 473**System API**: This is a system API and cannot be called by third-party applications. 474 475**Parameters** 476 477| Name| Type| Mandatory| Description| 478| -------- | -------- | -------- | -------- | 479| bundleName | string | Yes| Bundle name.| 480| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 481 482**Example** 483 484 ```ts 485 let bundleName = 'bundleName'; 486 function killProcessesByBundleNameCallback(err, data) { 487 if (err) { 488 console.log('------------- killProcessesByBundleNameCallback fail, err: --------------', err); 489 } else { 490 console.log('------------- killProcessesByBundleNameCallback success, data: --------------', data); 491 } 492 } 493 app.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); 494 ``` 495 496## appManager.killProcessesByBundleName<sup>8+</sup> 497 498killProcessesByBundleName(bundleName: string): Promise\<void>; 499 500Kills a process by bundle name. This API uses a promise to return the result. 501 502**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 503 504**System capability**: SystemCapability.Ability.AbilityRuntime.Core 505 506**System API**: This is a system API and cannot be called by third-party applications. 507 508**Parameters** 509 510| Name| Type| Mandatory| Description| 511| -------- | -------- | -------- | -------- | 512| bundleName | string | Yes| Bundle name.| 513 514**Return value** 515 516| Type| Description| 517| -------- | -------- | 518| Promise\<void> | Promise used to return the result.| 519 520**Example** 521 522 ```ts 523 let bundleName = 'bundleName'; 524 app.killProcessesByBundleName(bundleName) 525 .then((data) => { 526 console.log('------------ killProcessesByBundleName success ------------', data); 527 }) 528 .catch((err) => { 529 console.log('------------ killProcessesByBundleName fail ------------', err); 530 }); 531 ``` 532 533## appManager.clearUpApplicationData<sup>8+</sup> 534 535clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>); 536 537Clears application data by bundle name. This API uses an asynchronous callback to return the result. 538 539**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 540 541**System capability**: SystemCapability.Ability.AbilityRuntime.Core 542 543**System API**: This is a system API and cannot be called by third-party applications. 544 545**Parameters** 546 547| Name| Type| Mandatory| Description| 548| -------- | -------- | -------- | -------- | 549| bundleName | string | Yes| Bundle name.| 550| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 551 552**Example** 553 554 ```ts 555 let bundleName = 'bundleName'; 556 function clearUpApplicationDataCallback(err, data) { 557 if (err) { 558 console.log('------------- clearUpApplicationDataCallback fail, err: --------------', err); 559 } else { 560 console.log('------------- clearUpApplicationDataCallback success, data: --------------', data); 561 } 562 } 563 app.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); 564 ``` 565 566## appManager.clearUpApplicationData<sup>8+</sup> 567 568clearUpApplicationData(bundleName: string): Promise\<void>; 569 570Clears application data by bundle name. This API uses a promise to return the result. 571 572**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 573 574**System capability**: SystemCapability.Ability.AbilityRuntime.Core 575 576**System API**: This is a system API and cannot be called by third-party applications. 577 578**Parameters** 579 580| Name| Type| Mandatory| Description| 581| -------- | -------- | -------- | -------- | 582| bundleName | string | Yes| Bundle name.| 583 584**Return value** 585 586| Type| Description| 587| -------- | -------- | 588| Promise\<void> | Promise used to return the result.| 589 590**Example** 591 592 ```ts 593 let bundleName = 'bundleName'; 594 app.clearUpApplicationData(bundleName) 595 .then((data) => { 596 console.log('------------ clearUpApplicationData success ------------', data); 597 }) 598 .catch((err) => { 599 console.log('------------ clearUpApplicationData fail ------------', err); 600 }); 601 ``` 602