1# @ohos.app.ability.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 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. 8 9## Modules to Import 10 11```ts 12import appManager from '@ohos.app.ability.appManager'; 13``` 14 15## appManager.isRunningInStabilityTest 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 API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite. | 28 29**Error codes** 30 31| ID| Error Message| 32| ------- | -------- | 33| 16000050 | Internal error. | 34 35For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 36 37**Example** 38 39```ts 40import appManager from '@ohos.app.ability.appManager'; 41 42appManager.isRunningInStabilityTest((err, flag) => { 43 if (err) { 44 console.error(`isRunningInStabilityTest fail, err: ${JSON.stringify(err)}`); 45 } else { 46 console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`); 47 } 48}); 49``` 50 51 52## appManager.isRunningInStabilityTest 53 54static isRunningInStabilityTest(): Promise<boolean> 55 56Checks whether this application is undergoing a stability test. This API uses a promise to return the result. 57 58**System capability**: SystemCapability.Ability.AbilityRuntime.Core 59 60**Return value** 61 62 | Type| Description| 63 | -------- | -------- | 64 | Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.| 65 66**Error codes** 67 68| ID| Error Message| 69| ------- | -------- | 70| 16000050 | Internal error. | 71 72For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 73 74**Example** 75 76```ts 77import appManager from '@ohos.app.ability.appManager'; 78import { BusinessError } from '@ohos.base'; 79 80appManager.isRunningInStabilityTest().then((flag) => { 81 console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`); 82}).catch((error: BusinessError) => { 83 console.error(`error: ${JSON.stringify(error)}`); 84}); 85``` 86 87 88## appManager.isRamConstrainedDevice 89 90isRamConstrainedDevice(): Promise\<boolean>; 91 92Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result. 93 94**System capability**: SystemCapability.Ability.AbilityRuntime.Core 95 96**Return value** 97 98 | Type| Description| 99 | -------- | -------- | 100 | Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.| 101 102**Error codes** 103 104| ID| Error Message| 105| ------- | -------- | 106| 16000050 | Internal error. | 107 108For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 109 110**Example** 111 112```ts 113import appManager from '@ohos.app.ability.appManager'; 114import { BusinessError } from '@ohos.base'; 115 116appManager.isRamConstrainedDevice().then((data) => { 117 console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`); 118}).catch((error: BusinessError) => { 119 console.error(`error: ${JSON.stringify(error)}`); 120}); 121``` 122 123## appManager.isRamConstrainedDevice 124 125isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void; 126 127Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result. 128 129**System capability**: SystemCapability.Ability.AbilityRuntime.Core 130 131**Parameters** 132 133 | Name| Type| Mandatory| Description| 134 | -------- | -------- | -------- | -------- | 135 | callback | AsyncCallback<boolean> | Yes|Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite. | 136 137**Error codes** 138 139| ID| Error Message| 140| ------- | -------- | 141| 16000050 | Internal error. | 142 143For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 144 145**Example** 146 147```ts 148import appManager from '@ohos.app.ability.appManager'; 149 150appManager.isRamConstrainedDevice((err, data) => { 151 if (err) { 152 console.error(`isRamConstrainedDevice fail, err: ${JSON.stringify(err)}`); 153 } else { 154 console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`); 155 } 156}); 157``` 158 159## appManager.getAppMemorySize 160 161getAppMemorySize(): Promise\<number>; 162 163Obtains the memory size of this application. This API uses a promise to return the result. 164 165**System capability**: SystemCapability.Ability.AbilityRuntime.Core 166 167**Return value** 168 169 | Type| Description| 170 | -------- | -------- | 171 | Promise<number> | Promise used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.| 172 173**Error codes** 174 175| ID| Error Message| 176| ------- | -------- | 177| 16000050 | Internal error. | 178 179For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 180 181**Example** 182 183```ts 184import appManager from '@ohos.app.ability.appManager'; 185import { BusinessError} from '@ohos.base' 186 187appManager.getAppMemorySize().then((data) => { 188 console.log(`The size of app memory is: ${JSON.stringify(data)}`); 189}).catch((error: BusinessError) => { 190 console.error(`error: ${JSON.stringify(error)}`); 191}); 192``` 193 194## appManager.getAppMemorySize 195 196getAppMemorySize(callback: AsyncCallback\<number>): void; 197 198Obtains the memory size of this application. This API uses an asynchronous callback to return the result. 199 200**System capability**: SystemCapability.Ability.AbilityRuntime.Core 201 202**Parameters** 203 204 | Name| Type| Mandatory| Description| 205 | -------- | -------- | -------- | -------- | 206 | callback | AsyncCallback<number> | Yes|Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.| 207 208**Error codes** 209 210| ID| Error Message| 211| ------- | -------- | 212| 16000050 | Internal error. | 213 214For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 215 216**Example** 217 218```ts 219import appManager from '@ohos.app.ability.appManager'; 220 221appManager.getAppMemorySize((err, data) => { 222 if (err) { 223 console.error(`getAppMemorySize fail, err: ${JSON.stringify(err)}`); 224 } else { 225 console.log(`The size of app memory is: ${JSON.stringify(data)}`); 226 } 227}); 228``` 229 230## appManager.getRunningProcessInformation 231 232getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>; 233 234Obtains information about the running processes. This API uses a promise to return the result. 235 236**Required permissions**: ohos.permission.GET_RUNNING_INFO 237 238**System capability**: SystemCapability.Ability.AbilityRuntime.Core 239 240**Return value** 241 242| Type| Description| 243| -------- | -------- | 244| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| 245 246**Error codes** 247 248| ID| Error Message| 249| ------- | -------- | 250| 16000050 | Internal error. | 251 252For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 253 254**Example** 255 256```ts 257import appManager from '@ohos.app.ability.appManager'; 258import { BusinessError } from '@ohos.base'; 259 260appManager.getRunningProcessInformation().then((data) => { 261 console.log(`The running process information is: ${JSON.stringify(data)}`); 262}).catch((error: BusinessError) => { 263 console.error(`error: ${JSON.stringify(error)}`); 264}); 265``` 266 267## appManager.getRunningProcessInformation<sup>9+</sup> 268 269getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>>): void; 270 271Obtains information about the running processes. This API uses an asynchronous callback to return the result. 272 273**Required permissions**: ohos.permission.GET_RUNNING_INFO 274 275**System capability**: SystemCapability.Ability.AbilityRuntime.Core 276 277**Parameters** 278 279 | Name| Type| Mandatory| Description| 280 | -------- | -------- | -------- | -------- | 281 | callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | 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.| 282 283**Error codes** 284 285| ID| Error Message| 286| ------- | -------- | 287| 16000050 | Internal error. | 288 289For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 290 291**Example** 292 293```ts 294import appManager from '@ohos.app.ability.appManager'; 295 296appManager.getRunningProcessInformation((err, data) => { 297 if (err) { 298 console.error(`getRunningProcessInformation fail, err: ${JSON.stringify(err)}`); 299 } else { 300 console.log(`The process running information is: ${JSON.stringify(data)}`); 301 } 302}); 303``` 304 305## appManager.isSharedBundleRunning<sup>10+</sup> 306 307isSharedBundleRunning(bundleName: string, versionCode: number): Promise\<boolean>; 308 309Checks whether the shared library is in use. This API uses a promise to return the result. 310 311**Required permissions**: ohos.permission.GET_RUNNING_INFO 312 313**System capability**: SystemCapability.Ability.AbilityRuntime.Core 314 315**System API**: This is a system API. 316 317**Parameters** 318 319| Name | Type | Mandatory | Description | 320| --------- | ---------------------------------------- | ---- | -------------- | 321| bundleName | string | Yes | Bundle name of the shared library.| 322| versionCode | number | Yes | Version number of the shared library. | 323 324**Return value** 325 326| Type| Description| 327| -------- | -------- | 328| Promise\<boolean> | Promise used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.| 329 330**Error codes** 331 332| ID| Error Message| 333| ------- | -------- | 334| 16000050 | Internal error. | 335 336For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 337 338**Example** 339 340```ts 341import appManager from '@ohos.app.ability.appManager'; 342import { BusinessError } from '@ohos.base'; 343 344const bundleName = "this is a bundleName"; 345const versionCode = 1; 346appManager.isSharedBundleRunning(bundleName, versionCode).then((data) => { 347 console.log(`The shared bundle running is: ${JSON.stringify(data)}`); 348}).catch((error: BusinessError) => { 349 console.error(`error: ${JSON.stringify(error)}`); 350}); 351``` 352 353## appManager.isSharedBundleRunning<sup>10+</sup> 354 355isSharedBundleRunning(bundleName: string, versionCode: number, callback: AsyncCallback\<boolean>): void; 356 357Checks whether the shared library is in use. This API uses an asynchronous callback to return the result. 358 359**Required permissions**: ohos.permission.GET_RUNNING_INFO 360 361**System capability**: SystemCapability.Ability.AbilityRuntime.Core 362 363**System API**: This is a system API. 364 365**Parameters** 366 367| Name | Type | Mandatory | Description | 368| --------- | ---------------------------------------- | ---- | -------------- | 369| bundleName | string | Yes | Bundle name of the shared library.| 370| versionCode | number | Yes | Version number of the shared library. | 371|AsyncCallback\<boolean>> | Callback used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.| 372 373**Error codes** 374 375| ID| Error Message| 376| ------- | -------- | 377| 16000050 | Internal error. | 378 379For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 380 381**Example** 382 383```ts 384import appManager from '@ohos.app.ability.appManager'; 385 386const bundleName = "this is a bundleName"; 387const versionCode = 1; 388appManager.isSharedBundleRunning(bundleName, versionCode, (err, data) => { 389 if (err) { 390 console.error(`err: ${JSON.stringify(err)}`); 391 } else { 392 console.log(`The shared bundle running is: ${JSON.stringify(data)}`); 393 } 394}); 395``` 396 397## appManager.on 398 399on(type: 'applicationState', observer: ApplicationStateObserver): number; 400 401Registers an observer to listen for the state changes of all applications. 402 403**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 404 405**System capability**: SystemCapability.Ability.AbilityRuntime.Core 406 407**System API**: This is a system API and cannot be called by third-party applications. 408 409**Parameters** 410 411| Name| Type| Mandatory| Description| 412| -------- | -------- | -------- | -------- | 413| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 414| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 415 416**Return value** 417 418| Type| Description| 419| --- | --- | 420| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 421 422**Error codes** 423 424| ID| Error Message| 425| ------- | -------- | 426| 16000050 | Internal error. | 427 428For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 429 430**Example** 431 432```ts 433import appManager from '@ohos.app.ability.appManager'; 434import { BusinessError } from '@ohos.base'; 435 436let applicationStateObserver: appManager.ApplicationStateObserver = { 437 onForegroundApplicationChanged(appStateData) { 438 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 439 }, 440 onAbilityStateChanged(abilityStateData) { 441 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 442 }, 443 onProcessCreated(processData) { 444 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 445 }, 446 onProcessDied(processData) { 447 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 448 }, 449 onProcessStateChanged(processData) { 450 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 451 } 452}; 453try { 454 const observerId = appManager.on('applicationState', applicationStateObserver); 455 console.log(`[appManager] observerCode: ${observerId}`); 456} catch (paramError) { 457 let code = (paramError as BusinessError).code; 458 let message = (paramError as BusinessError).message; 459 console.error(`[appManager] error: ${code}, ${message} `); 460} 461``` 462 463## appManager.on 464 465on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number; 466 467Registers an observer to listen for the state changes of a specified application. 468 469**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 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| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 480| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 481| bundleNameList | `Array<string>` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.| 482 483**Return value** 484 485| Type| Description| 486| --- | --- | 487| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 488 489**Error codes** 490 491| ID| Error Message| 492| ------- | -------- | 493| 16000050 | Internal error. | 494 495For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 496 497**Example** 498 499```ts 500import appManager from '@ohos.app.ability.appManager'; 501import { BusinessError } from '@ohos.base'; 502 503let applicationStateObserver: appManager.ApplicationStateObserver = { 504 onForegroundApplicationChanged(appStateData) { 505 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 506 }, 507 onAbilityStateChanged(abilityStateData) { 508 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 509 }, 510 onProcessCreated(processData) { 511 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 512 }, 513 onProcessDied(processData) { 514 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 515 }, 516 onProcessStateChanged(processData) { 517 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 518 } 519}; 520let bundleNameList = ['bundleName1', 'bundleName2']; 521try { 522 const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 523 console.log(`[appManager] observerCode: ${observerId}`); 524} catch (paramError) { 525 let code = (paramError as BusinessError).code; 526 let message = (paramError as BusinessError).message; 527 console.error(`[appManager] error: ${code}, ${message} `); 528} 529``` 530 531## appManager.off 532 533off(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>): void; 534 535Deregisters the application state observer. This API uses an asynchronous callback to return the result. 536 537**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 538 539**System capability**: SystemCapability.Ability.AbilityRuntime.Core 540 541**System API**: This is a system API and cannot be called by third-party applications. 542 543**Parameters** 544 545| Name| Type| Mandatory| Description| 546| -------- | -------- | -------- | -------- | 547| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 548| observerId | number | Yes| Digital code of the observer.| 549| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 550 551**Error codes** 552 553| ID| Error Message| 554| ------- | -------- | 555| 16000050 | Internal error. | 556 557For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 558 559**Example** 560 561```ts 562import appManager from '@ohos.app.ability.appManager'; 563import { BusinessError } from '@ohos.base'; 564 565let observerId = 0; 566 567// 1. Register an application state observer. 568let applicationStateObserver: appManager.ApplicationStateObserver = { 569 onForegroundApplicationChanged(appStateData) { 570 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 571 }, 572 onAbilityStateChanged(abilityStateData) { 573 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 574 }, 575 onProcessCreated(processData) { 576 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 577 }, 578 onProcessDied(processData) { 579 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 580 }, 581 onProcessStateChanged(processData) { 582 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 583 } 584}; 585let bundleNameList = ['bundleName1', 'bundleName2']; 586try { 587 observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 588 console.log(`[appManager] observerCode: ${observerId}`); 589} catch (paramError) { 590 let code = (paramError as BusinessError).code; 591 let message = (paramError as BusinessError).message; 592 console.error(`[appManager] error: ${code}, ${message} `); 593} 594 595// 2. Deregister the application state observer. 596function unregisterApplicationStateObserverCallback(err: BusinessError) { 597 if (err) { 598 console.error(`unregisterApplicationStateObserverCallback fail, err: ${JSON.stringify(err)}`); 599 } else { 600 console.log('unregisterApplicationStateObserverCallback success.'); 601 } 602} 603try { 604 appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback); 605} catch (paramError) { 606 let code = (paramError as BusinessError).code; 607 let message = (paramError as BusinessError).message; 608 console.error(`[appManager] error: ${code}, ${message} `); 609} 610``` 611 612## appManager.off 613 614off(type: 'applicationState', observerId: number): Promise\<void>; 615 616Deregisters the application state observer. This API uses an asynchronous callback to return the result. 617 618**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 619 620**System capability**: SystemCapability.Ability.AbilityRuntime.Core 621 622**System API**: This is a system API and cannot be called by third-party applications. 623 624**Parameters** 625 626| Name| Type| Mandatory| Description| 627| -------- | -------- | -------- | -------- | 628| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 629| observerId | number | Yes| Digital code of the observer.| 630 631**Return value** 632 633| Type| Description| 634| -------- | -------- | 635| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 636 637**Error codes** 638 639| ID| Error Message| 640| ------- | -------- | 641| 16000050 | Internal error. | 642 643For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 644 645**Example** 646 647```ts 648import appManager from '@ohos.app.ability.appManager'; 649import { BusinessError } from '@ohos.base'; 650 651let observerId = 0; 652 653// 1. Register an application state observer. 654let applicationStateObserver: appManager.ApplicationStateObserver = { 655 onForegroundApplicationChanged(appStateData) { 656 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 657 }, 658 onAbilityStateChanged(abilityStateData) { 659 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 660 }, 661 onProcessCreated(processData) { 662 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 663 }, 664 onProcessDied(processData) { 665 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 666 }, 667 onProcessStateChanged(processData) { 668 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 669 } 670}; 671let bundleNameList = ['bundleName1', 'bundleName2']; 672try { 673 observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 674} catch (paramError) { 675 let code = (paramError as BusinessError).code; 676 let message = (paramError as BusinessError).message; 677 console.error(`[appManager] error: ${code}, ${message} `); 678} 679 680// 2. Deregister the application state observer. 681try { 682 appManager.off('applicationState', observerId).then((data) => { 683 console.log(`unregisterApplicationStateObserver success, data: ${JSON.stringify(data)}`); 684 }).catch((err: BusinessError) => { 685 console.error(`unregisterApplicationStateObserver fail, err: ${JSON.stringify(err)}`); 686 }); 687} catch (paramError) { 688 let code = (paramError as BusinessError).code; 689 let message = (paramError as BusinessError).message; 690 console.error(`[appManager] error: ${code}, ${message} `); 691} 692``` 693 694## appManager.getForegroundApplications 695 696getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void; 697 698Obtains 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). 699 700**Required permissions**: ohos.permission.GET_RUNNING_INFO 701 702**System capability**: SystemCapability.Ability.AbilityRuntime.Core 703 704**System API**: This is a system API and cannot be called by third-party applications. 705 706**Error codes** 707 708| ID| Error Message| 709| ------- | -------- | 710| 16000050 | Internal error. | 711 712For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 713 714**Parameters** 715 716| Name| Type| Mandatory| Description| 717| -------- | -------- | -------- | -------- | 718| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | 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.| 719 720**Example** 721 722```ts 723import appManager from '@ohos.app.ability.appManager'; 724import { BusinessError } from '@ohos.base'; 725 726function getForegroundApplicationsCallback(err: BusinessError, data: Array<appManager.AppStateData>) { 727 if (err) { 728 console.error(`getForegroundApplicationsCallback fail, err: ${JSON.stringify(err)}`); 729 } else { 730 console.log(`getForegroundApplicationsCallback success, data: ${JSON.stringify(data)}`); 731 } 732} 733try { 734 appManager.getForegroundApplications(getForegroundApplicationsCallback); 735} catch (paramError) { 736 let code = (paramError as BusinessError).code; 737 let message = (paramError as BusinessError).message; 738 console.error(`[appManager] error: ${code}, ${message} `); 739} 740``` 741 742## appManager.getForegroundApplications 743 744getForegroundApplications(): Promise\<Array\<AppStateData>>; 745 746Obtains 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). 747 748**Required permissions**: ohos.permission.GET_RUNNING_INFO 749 750**System capability**: SystemCapability.Ability.AbilityRuntime.Core 751 752**System API**: This is a system API and cannot be called by third-party applications. 753 754**Return value** 755 756| Type| Description| 757| -------- | -------- | 758| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Promise used to return an array holding the application state data.| 759 760**Error codes** 761 762| ID| Error Message| 763| ------- | -------- | 764| 16000050 | Internal error. | 765 766For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 767 768**Example** 769 770```ts 771import appManager from '@ohos.app.ability.appManager'; 772import { BusinessError } from '@ohos.base'; 773 774appManager.getForegroundApplications().then((data) => { 775 console.log(`getForegroundApplications success, data: ${JSON.stringify(data)}`); 776}).catch((err: BusinessError) => { 777 console.error(`getForegroundApplications fail, err: ${JSON.stringify(err)}`); 778}); 779``` 780 781## appManager.killProcessWithAccount 782 783killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\> 784 785Kills a process by bundle name and account ID. This API uses a promise to return the result. 786 787> **NOTE** 788> 789> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 790 791**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES 792 793**System capability**: SystemCapability.Ability.AbilityRuntime.Core 794 795**System API**: This is a system API and cannot be called by third-party applications. 796 797**Parameters** 798 799| Name| Type| Mandatory| Description| 800| -------- | -------- | -------- | -------- | 801| bundleName | string | Yes| Bundle name.| 802| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).| 803 804**Error codes** 805 806| ID| Error Message| 807| ------- | -------- | 808| 16000050 | Internal error. | 809 810For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 811 812**Example** 813 814```ts 815import appManager from '@ohos.app.ability.appManager'; 816import { BusinessError } from '@ohos.base'; 817 818let bundleName = 'bundleName'; 819let accountId = 0; 820try { 821 appManager.killProcessWithAccount(bundleName, accountId).then(() => { 822 console.log('killProcessWithAccount success'); 823 }).catch((err: BusinessError) => { 824 console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`); 825 }); 826} catch (paramError) { 827 let code = (paramError as BusinessError).code; 828 let message = (paramError as BusinessError).message; 829 console.error(`[appManager] error: ${code}, ${message} `); 830} 831``` 832 833 834## appManager.killProcessWithAccount 835 836killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void 837 838Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result. 839 840> **NOTE** 841> 842> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 843 844**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES 845 846**System capability**: SystemCapability.Ability.AbilityRuntime.Core 847 848**System API**: This is a system API and cannot be called by third-party applications. 849 850**Parameters** 851 852 | Name| Type| Mandatory| Description| 853 | -------- | -------- | -------- | -------- | 854 | bundleName | string | Yes| Bundle name.| 855 | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).| 856 | callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 857 858**Error codes** 859 860| ID| Error Message| 861| ------- | -------- | 862| 16000050 | Internal error. | 863 864For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 865 866**Example** 867 868```ts 869import appManager from '@ohos.app.ability.appManager'; 870import { BusinessError } from '@ohos.base'; 871 872let bundleName = 'bundleName'; 873let accountId = 0; 874function killProcessWithAccountCallback(err: BusinessError) { 875 if (err) { 876 console.error(`killProcessWithAccountCallback fail, err: ${JSON.stringify(err)}`); 877 } else { 878 console.log('killProcessWithAccountCallback success.'); 879 } 880} 881appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); 882``` 883 884## appManager.killProcessesByBundleName 885 886killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>); 887 888Kills a process by bundle name. This API uses an asynchronous callback to return the result. 889 890**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 891 892**System capability**: SystemCapability.Ability.AbilityRuntime.Core 893 894**System API**: This is a system API and cannot be called by third-party applications. 895 896**Parameters** 897 898| Name| Type| Mandatory| Description| 899| -------- | -------- | -------- | -------- | 900| bundleName | string | Yes| Bundle name.| 901| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 902 903**Error codes** 904 905| ID| Error Message| 906| ------- | -------- | 907| 16000050 | Internal error. | 908 909For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 910 911**Example** 912 913```ts 914import appManager from '@ohos.app.ability.appManager'; 915import { BusinessError } from '@ohos.base'; 916 917let bundleName = 'bundleName'; 918function killProcessesByBundleNameCallback(err: BusinessError) { 919 if (err) { 920 console.error(`killProcessesByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 921 } else { 922 console.log('killProcessesByBundleNameCallback success.'); 923 } 924} 925try { 926 appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); 927} catch (paramError) { 928 let code = (paramError as BusinessError).code; 929 let message = (paramError as BusinessError).message; 930 console.error(`[appManager] error: ${code}, ${message} `); 931} 932``` 933 934## appManager.killProcessesByBundleName 935 936killProcessesByBundleName(bundleName: string): Promise\<void>; 937 938Kills a process by bundle name. This API uses a promise to return the result. 939 940**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 941 942**System capability**: SystemCapability.Ability.AbilityRuntime.Core 943 944**System API**: This is a system API and cannot be called by third-party applications. 945 946**Parameters** 947 948| Name| Type| Mandatory| Description| 949| -------- | -------- | -------- | -------- | 950| bundleName | string | Yes| Bundle name.| 951 952**Return value** 953 954| Type| Description| 955| -------- | -------- | 956| Promise\<void> | Promise used to return the result.| 957 958**Error codes** 959 960| ID| Error Message| 961| ------- | -------- | 962| 16000050 | Internal error. | 963 964For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 965 966**Example** 967 968```ts 969import appManager from '@ohos.app.ability.appManager'; 970import { BusinessError } from '@ohos.base'; 971 972let bundleName = 'bundleName'; 973try { 974 appManager.killProcessesByBundleName(bundleName).then((data) => { 975 console.log('killProcessesByBundleName success.'); 976 }).catch((err: BusinessError) => { 977 console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`); 978 }); 979} catch (paramError) { 980 let code = (paramError as BusinessError).code; 981 let message = (paramError as BusinessError).message; 982 console.error(`[appManager] error: ${code}, ${message} `); 983} 984``` 985 986## appManager.clearUpApplicationData 987 988clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>); 989 990Clears application data by bundle name. This API uses an asynchronous callback to return the result. 991 992**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 993 994**System capability**: SystemCapability.Ability.AbilityRuntime.Core 995 996**System API**: This is a system API and cannot be called by third-party applications. 997 998**Parameters** 999 1000| Name| Type| Mandatory| Description| 1001| -------- | -------- | -------- | -------- | 1002| bundleName | string | Yes| Bundle name.| 1003| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 1004 1005**Error codes** 1006 1007| ID| Error Message| 1008| ------- | -------- | 1009| 16000050 | Internal error. | 1010 1011For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1012 1013**Example** 1014 1015```ts 1016import appManager from '@ohos.app.ability.appManager'; 1017import { BusinessError } from '@ohos.base'; 1018 1019let bundleName = 'bundleName'; 1020function clearUpApplicationDataCallback(err: BusinessError) { 1021 if (err) { 1022 console.error(`clearUpApplicationDataCallback fail, err: ${JSON.stringify(err)}`); 1023 } else { 1024 console.log('clearUpApplicationDataCallback success.'); 1025 } 1026} 1027try { 1028 appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); 1029} catch (paramError) { 1030 let code = (paramError as BusinessError).code; 1031 let message = (paramError as BusinessError).message; 1032 console.error(`[appManager] error: ${code}, ${message} `); 1033} 1034``` 1035 1036## appManager.clearUpApplicationData 1037 1038clearUpApplicationData(bundleName: string): Promise\<void>; 1039 1040Clears application data by bundle name. This API uses a promise to return the result. 1041 1042**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 1043 1044**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1045 1046**System API**: This is a system API and cannot be called by third-party applications. 1047 1048**Parameters** 1049 1050| Name| Type| Mandatory| Description| 1051| -------- | -------- | -------- | -------- | 1052| bundleName | string | Yes| Bundle name.| 1053 1054**Return value** 1055 1056| Type| Description| 1057| -------- | -------- | 1058| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 1059 1060**Error codes** 1061 1062| ID| Error Message| 1063| ------- | -------- | 1064| 16000050 | Internal error. | 1065 1066For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1067 1068**Example** 1069 1070```ts 1071import appManager from '@ohos.app.ability.appManager'; 1072import { BusinessError } from '@ohos.base'; 1073 1074let bundleName = 'bundleName'; 1075try { 1076 appManager.clearUpApplicationData(bundleName).then((data) => { 1077 console.log('clearUpApplicationData success.'); 1078 }).catch((err: BusinessError) => { 1079 console.error(`clearUpApplicationData fail, err: ${JSON.stringify(err)}`); 1080 }); 1081} catch (paramError) { 1082 let code = (paramError as BusinessError).code; 1083 let message = (paramError as BusinessError).message; 1084 console.error(`[appManager] error: ${code}, ${message} `); 1085} 1086``` 1087 1088## appManager.getProcessMemoryByPid<sup>10+</sup> 1089 1090getProcessMemoryByPid(pid: number, callback: AsyncCallback\<number>): void; 1091 1092Obtains the memory size of a process. This API uses an asynchronous callback to return the result. 1093 1094**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1095 1096**System API**: This is a system API. 1097 1098**Parameters** 1099 1100| Name| Type| Mandatory| Description| 1101| -------- | -------- | -------- | -------- | 1102| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinfobybundlename10).| 1103| callback | AsyncCallback\<number> | 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.| 1104 1105**Error codes** 1106 1107For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1108 1109| ID| Error Message| 1110| ------- | -------- | 1111| 16000050 | Internal error. | 1112 1113**Example** 1114 1115```ts 1116import appManager from '@ohos.app.ability.appManager'; 1117import { BusinessError } from '@ohos.base'; 1118 1119let pid = 0; 1120function getProcessMemoryByPidCallback(err: BusinessError, data: number) { 1121 if (err) { 1122 console.error(`getProcessMemoryByPidCallback fail, err: ${JSON.stringify(err)}`); 1123 } else { 1124 console.log('getProcessMemoryByPidCallback success.'); 1125 } 1126} 1127try { 1128 appManager.getProcessMemoryByPid(pid, getProcessMemoryByPidCallback); 1129} catch (paramError) { 1130 let code = (paramError as BusinessError).code; 1131 let message = (paramError as BusinessError).message; 1132 console.error(`[appManager] error: ${code}, ${message} `); 1133} 1134``` 1135 1136## appManager.getProcessMemoryByPid<sup>10+</sup> 1137 1138getProcessMemoryByPid(pid: number): Promise\<number>; 1139 1140Obtains the memory size of a process. This API uses a promise to return the result. 1141 1142**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1143 1144**System API**: This is a system API. 1145 1146**Parameters** 1147 1148| Name| Type| Mandatory| Description| 1149| -------- | -------- | -------- | -------- | 1150| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinfobybundlename10). | 1151 1152**Return value** 1153 1154| Type| Description| 1155| -------- | -------- | 1156| Promise\<number> | 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.| 1157 1158**Error codes** 1159 1160For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1161 1162| ID| Error Message| 1163| ------- | -------- | 1164| 16000050 | Internal error. | 1165 1166**Example** 1167 1168```ts 1169import appManager from '@ohos.app.ability.appManager'; 1170import { BusinessError } from '@ohos.base'; 1171 1172let pid = 0; 1173try { 1174 appManager.getProcessMemoryByPid(pid).then((data) => { 1175 console.log('getProcessMemoryByPid success.'); 1176 }).catch((err: BusinessError) => { 1177 console.error(`getProcessMemoryByPid fail, err: ${JSON.stringify(err)}`); 1178 }); 1179} catch (paramError) { 1180 let code = (paramError as BusinessError).code; 1181 let message = (paramError as BusinessError).message; 1182 console.error(`[appManager] error: ${code}, ${message} `); 1183} 1184``` 1185 1186## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1187 1188getRunningProcessInfoByBundleName(bundleName: string, callback: AsyncCallback\<Array\<ProcessInformation>>): void; 1189 1190Obtains information about the running processes by bundle name. This API uses an asynchronous callback to return the result. 1191 1192**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1193 1194**System API**: This is a system API. 1195 1196**Parameters** 1197 1198| Name| Type| Mandatory| Description| 1199| -------- | -------- | -------- | -------- | 1200| bundleName | string | Yes| Bundle name.| 1201| callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | 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.| 1202 1203**Error codes** 1204 1205For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1206 1207| ID| Error Message| 1208| ------- | -------- | 1209| 16000050 | Internal error. | 1210 1211**Example** 1212 1213```ts 1214import appManager from '@ohos.app.ability.appManager'; 1215import { BusinessError } from '@ohos.base'; 1216 1217let bundleName = "bundleName"; 1218function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: appManager.Array<ProcessInformation>) { 1219 if (err) { 1220 console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 1221 } else { 1222 console.log('getRunningProcessInfoByBundleNameCallback success.'); 1223 } 1224} 1225try { 1226 appManager.getRunningProcessInfoByBundleName(bundleName, getRunningProcessInfoByBundleNameCallback); 1227} catch (paramError) { 1228 let code = (paramError as BusinessError).code; 1229 let message = (paramError as BusinessError).message; 1230 console.error(`[appManager] error: ${code}, ${message} `); 1231} 1232``` 1233 1234## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1235 1236getRunningProcessInfoByBundleName(bundleName: string): Promise\<Array\<ProcessInformation>>; 1237 1238Obtains information about the running processes by bundle name. This API uses a promise to return the result. 1239 1240**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1241 1242**System API**: This is a system API. 1243 1244**Parameters** 1245 1246| Name| Type| Mandatory| Description| 1247| -------- | -------- | -------- | -------- | 1248| bundleName | string | Yes| Bundle name.| 1249 1250**Return value** 1251 1252| Type| Description| 1253| -------- | -------- | 1254| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| 1255 1256**Error codes** 1257 1258For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1259 1260| ID| Error Message| 1261| ------- | -------- | 1262| 16000050 | Internal error. | 1263 1264**Example** 1265 1266```ts 1267import appManager from '@ohos.app.ability.appManager'; 1268import { BusinessError } from '@ohos.base'; 1269 1270let bundleName = "bundleName"; 1271try { 1272 appManager.getRunningProcessInfoByBundleName(bundleName).then((data) => { 1273 console.log('getRunningProcessInfoByBundleName success.'); 1274 }).catch((err: BusinessError) => { 1275 console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`); 1276 }); 1277} catch (paramError) { 1278 let code = (paramError as BusinessError).code; 1279 let message = (paramError as BusinessError).message; 1280 console.error(`[appManager] error: ${code}, ${message} `); 1281} 1282``` 1283 1284## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1285 1286getRunningProcessInfoByBundleName(bundleName: string, userId: number, callback: AsyncCallback\<Array\<ProcessInformation>>): void; 1287 1288Obtains information about the running processes by bundle name and user ID. This API uses an asynchronous callback to return the result. 1289 1290**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1291 1292**System API**: This is a system API. 1293 1294**Parameters** 1295 1296| Name| Type| Mandatory| Description| 1297| -------- | -------- | -------- | -------- | 1298| bundleName | string | Yes| Bundle name.| 1299| userId | number | Yes| User ID.| 1300| callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | 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.| 1301 1302**Error codes** 1303 1304For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1305 1306| ID| Error Message| 1307| ------- | -------- | 1308| 16000050 | Internal error. | 1309 1310**Example** 1311 1312```ts 1313import appManager from '@ohos.app.ability.appManager'; 1314import { BusinessError } from '@ohos.base'; 1315 1316let bundleName = "bundleName"; 1317let userId = 0; 1318function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) { 1319 if (err) { 1320 console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 1321 } else { 1322 console.log('getRunningProcessInfoByBundleNameCallback success.'); 1323 } 1324} 1325try { 1326 appManager.getRunningProcessInfoByBundleName(bundleName, userId, getRunningProcessInfoByBundleNameCallback); 1327} catch (paramError) { 1328 let code = (paramError as BusinessError).code; 1329 let message = (paramError as BusinessError).message; 1330 console.error(`[appManager] error: ${code}, ${message} `); 1331} 1332``` 1333 1334## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1335 1336getRunningProcessInfoByBundleName(bundleName: string, userId: number): Promise\<Array\<ProcessInformation>>; 1337 1338Obtains information about the running processes by bundle name and user ID. This API uses a promise to return the result. 1339 1340**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1341 1342**System API**: This is a system API. 1343 1344**Parameters** 1345 1346| Name| Type| Mandatory| Description| 1347| -------- | -------- | -------- | -------- | 1348| bundleName | string | Yes| Bundle name.| 1349| userId | number | Yes| User ID.| 1350 1351**Return value** 1352 1353| Type| Description| 1354| -------- | -------- | 1355| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| 1356 1357**Error codes** 1358 1359For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1360 1361| ID| Error Message| 1362| ------- | -------- | 1363| 16000050 | Internal error. | 1364 1365**Example** 1366 1367```ts 1368import appManager from '@ohos.app.ability.appManager'; 1369import { BusinessError } from '@ohos.base'; 1370 1371let bundleName = "bundleName"; 1372let userId = 0; 1373try { 1374 appManager.getRunningProcessInfoByBundleName(bundleName, userId).then((data) => { 1375 console.log('getRunningProcessInfoByBundleName success.'); 1376 }).catch((err: BusinessError) => { 1377 console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`); 1378 }); 1379} catch (paramError) { 1380 let code = (paramError as BusinessError).code; 1381 let message = (paramError as BusinessError).message; 1382 console.error(`[appManager] error: ${code}, ${message} `); 1383} 1384``` 1385 1386## ApplicationState 1387 1388Enumerates the application states. This enum can be used together with [AbilityStateData](js-apis-inner-application-appStateData.md) to return the application state. 1389 1390**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1391 1392**System API**: This is a system API and cannot be called by third-party applications. 1393 1394| Name | Value | Description | 1395| -------------------- | --- | --------------------------------- | 1396| STATE_CREATE | 1 | State indicating that the application is being created. | 1397| STATE_FOREGROUND | 2 | State indicating that the application is running in the foreground. | 1398| STATE_ACTIVE | 3 | State indicating that the application is active. | 1399| STATE_BACKGROUND | 4 | State indicating that the application is running in the background. | 1400| STATE_DESTROY | 5 | State indicating that the application is destroyed. | 1401 1402## ProcessState<sup>10+</sup> 1403 1404Enumerates the process states. This enum can be used together with [ProcessData](js-apis-inner-application-processData.md) to return the process state. 1405 1406**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1407 1408| Name | Value | Description | 1409| -------------------- | --- | --------------------------------- | 1410| STATE_CREATE | 0 | State indicating that the process is being created. | 1411| STATE_FOREGROUND | 1 | State indicating that the process is running in the foreground. | 1412| STATE_ACTIVE | 2 | State indicating that the process is active. | 1413| STATE_BACKGROUND | 3 | State indicating that the process is running in the background. | 1414| STATE_DESTROY | 4 | State indicating that the process is destroyed. | 1415