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 | Type| Description| 26 | -------- | -------- | 27 |AsyncCallback<boolean> |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.code !== 0) { 44 console.log('isRunningInStabilityTest faile, 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'; 78 79appManager.isRunningInStabilityTest().then((flag) => { 80 console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag)); 81}).catch((error) => { 82 console.log('error:' + JSON.stringify(error)); 83}); 84``` 85 86 87## appManager.isRamConstrainedDevice 88 89isRamConstrainedDevice(): Promise\<boolean>; 90 91Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result. 92 93**System capability**: SystemCapability.Ability.AbilityRuntime.Core 94 95**Return value** 96 97 | Type| Description| 98 | -------- | -------- | 99 | 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.| 100 101**Error codes** 102 103| ID| Error Message| 104| ------- | -------- | 105| 16000050 | Internal error. | 106 107For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 108 109**Example** 110 111```ts 112import appManager from '@ohos.app.ability.appManager'; 113 114appManager.isRamConstrainedDevice().then((data) => { 115 console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data)); 116}).catch((error) => { 117 console.log('error:' + JSON.stringify(error)); 118}); 119``` 120 121## appManager.isRamConstrainedDevice 122 123isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void; 124 125Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result. 126 127**System capability**: SystemCapability.Ability.AbilityRuntime.Core 128 129**Parameters** 130 131 | Type| Description| 132 | -------- | -------- | 133 | AsyncCallback<boolean> |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.| 134 135**Error codes** 136 137| ID| Error Message| 138| ------- | -------- | 139| 16000050 | Internal error. | 140 141For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 142 143**Example** 144 145```ts 146import appManager from '@ohos.app.ability.appManager'; 147 148appManager.isRamConstrainedDevice((err, data) => { 149 if (err.code !== 0) { 150 console.log('isRamConstrainedDevice faile, err: ' + JSON.stringify(err)); 151 } else { 152 console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data)); 153 } 154}); 155``` 156 157## appManager.getAppMemorySize 158 159getAppMemorySize(): Promise\<number>; 160 161Obtains the memory size of this application. This API uses a promise to return the result. 162 163**System capability**: SystemCapability.Ability.AbilityRuntime.Core 164 165**Return value** 166 167 | Type| Description| 168 | -------- | -------- | 169 | 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.| 170 171**Error codes** 172 173| ID| Error Message| 174| ------- | -------- | 175| 16000050 | Internal error. | 176 177For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 178 179**Example** 180 181```ts 182import appManager from '@ohos.app.ability.appManager'; 183 184appManager.getAppMemorySize().then((data) => { 185 console.log('The size of app memory is:' + JSON.stringify(data)); 186}).catch((error) => { 187 console.log('error:' + JSON.stringify(error)); 188}); 189``` 190 191## appManager.getAppMemorySize 192 193getAppMemorySize(callback: AsyncCallback\<number>): void; 194 195Obtains the memory size of this application. This API uses an asynchronous callback to return the result. 196 197**System capability**: SystemCapability.Ability.AbilityRuntime.Core 198 199**Parameters** 200 201 | Type| Description| 202 | -------- | -------- | 203 |AsyncCallback<number> |Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.| 204 205**Error codes** 206 207| ID| Error Message| 208| ------- | -------- | 209| 16000050 | Internal error. | 210 211For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 212 213**Example** 214 215```ts 216import appManager from '@ohos.app.ability.appManager'; 217 218appManager.getAppMemorySize((err, data) => { 219 if (err.code !== 0) { 220 console.log('getAppMemorySize faile, err: ' + JSON.stringify(err)); 221 } else { 222 console.log('The size of app memory is:' + JSON.stringify(data)); 223 } 224}); 225``` 226 227## appManager.getRunningProcessInformation 228 229getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>; 230 231Obtains information about the running processes. This API uses a promise to return the result. 232 233**Required permissions**: ohos.permission.GET_RUNNING_INFO 234 235**System capability**: SystemCapability.Ability.AbilityRuntime.Core 236 237**Return value** 238 239| Type| Description| 240| -------- | -------- | 241| 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.| 242 243**Error codes** 244 245| ID| Error Message| 246| ------- | -------- | 247| 16000050 | Internal error. | 248 249For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 250 251**Example** 252 253```ts 254import appManager from '@ohos.app.ability.appManager'; 255 256appManager.getRunningProcessInformation().then((data) => { 257 console.log('The running process information is:' + JSON.stringify(data)); 258}).catch((error) => { 259 console.log('error:' + JSON.stringify(error)); 260}); 261``` 262 263## appManager.getRunningProcessInformation<sup>9+</sup> 264 265getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>>): void; 266 267Obtains information about the running processes. This API uses an asynchronous callback to return the result. 268 269**Required permissions**: ohos.permission.GET_RUNNING_INFO 270 271**System capability**: SystemCapability.Ability.AbilityRuntime.Core 272 273**Parameters** 274 275| Type| Description| 276| -------- | -------- | 277|AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| 278 279**Error codes** 280 281| ID| Error Message| 282| ------- | -------- | 283| 16000050 | Internal error. | 284 285For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 286 287**Example** 288 289```ts 290import appManager from '@ohos.app.ability.appManager'; 291 292appManager.getRunningProcessInformation((err, data) => { 293 if (err.code !== 0) { 294 console.log('getRunningProcessInformation faile, err: ' + JSON.stringify(err)); 295 } else { 296 console.log('The process running information is:' + JSON.stringify(data)); 297 } 298}); 299``` 300 301## appManager.on 302 303on(type: 'applicationState', observer: ApplicationStateObserver): number; 304 305Registers an observer to listen for the state changes of all applications. 306 307**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 308 309**System capability**: SystemCapability.Ability.AbilityRuntime.Core 310 311**System API**: This is a system API and cannot be called by third-party applications. 312 313**Parameters** 314 315| Name| Type| Mandatory| Description| 316| -------- | -------- | -------- | -------- | 317| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 318| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 319 320**Return value** 321 322| Type| Description| 323| --- | --- | 324| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 325 326**Error codes** 327 328| ID| Error Message| 329| ------- | -------- | 330| 16000050 | Internal error. | 331 332For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 333 334**Example** 335 336```ts 337import appManager from '@ohos.app.ability.appManager'; 338 339let applicationStateObserver = { 340 onForegroundApplicationChanged(appStateData) { 341 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 342 }, 343 onAbilityStateChanged(abilityStateData) { 344 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 345 }, 346 onProcessCreated(processData) { 347 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 348 }, 349 onProcessDied(processData) { 350 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 351 }, 352 onProcessStateChanged(processData) { 353 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 354 } 355}; 356try { 357 const observerId = appManager.on('applicationState', applicationStateObserver); 358 console.log(`[appManager] observerCode: ${observerId}`); 359} catch (paramError) { 360 console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `); 361} 362``` 363 364## appManager.on 365 366on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number; 367 368Registers an observer to listen for the state changes of a specified application. 369 370**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 371 372**System capability**: SystemCapability.Ability.AbilityRuntime.Core 373 374**System API**: This is a system API and cannot be called by third-party applications. 375 376**Parameters** 377 378| Name| Type| Mandatory| Description| 379| -------- | -------- | -------- | -------- | 380| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 381| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 382| bundleNameList | `Array<string>` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.| 383 384**Return value** 385 386| Type| Description| 387| --- | --- | 388| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 389 390**Error codes** 391 392| ID| Error Message| 393| ------- | -------- | 394| 16000050 | Internal error. | 395 396For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 397 398**Example** 399 400```ts 401import appManager from '@ohos.app.ability.appManager'; 402 403let applicationStateObserver = { 404 onForegroundApplicationChanged(appStateData) { 405 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 406 }, 407 onAbilityStateChanged(abilityStateData) { 408 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 409 }, 410 onProcessCreated(processData) { 411 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 412 }, 413 onProcessDied(processData) { 414 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 415 }, 416 onProcessStateChanged(processData) { 417 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 418 } 419}; 420let bundleNameList = ['bundleName1', 'bundleName2']; 421try { 422 const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 423 console.log(`[appManager] observerCode: ${observerId}`); 424} catch (paramError) { 425 console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `); 426} 427``` 428 429## appManager.off 430 431off(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>): void; 432 433Deregisters the application state observer. This API uses an asynchronous callback to return the result. 434 435**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 436 437**System capability**: SystemCapability.Ability.AbilityRuntime.Core 438 439**System API**: This is a system API and cannot be called by third-party applications. 440 441**Parameters** 442 443| Name| Type| Mandatory| Description| 444| -------- | -------- | -------- | -------- | 445| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 446| observerId | number | Yes| Digital code of the observer.| 447| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 448 449**Error codes** 450 451| ID| Error Message| 452| ------- | -------- | 453| 16000050 | Internal error. | 454 455For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 456 457**Example** 458 459```ts 460import appManager from '@ohos.app.ability.appManager'; 461 462let observerId = 0; 463 464// 1. Register an application state observer. 465let applicationStateObserver = { 466 onForegroundApplicationChanged(appStateData) { 467 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 468 }, 469 onAbilityStateChanged(abilityStateData) { 470 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 471 }, 472 onProcessCreated(processData) { 473 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 474 }, 475 onProcessDied(processData) { 476 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 477 }, 478 onProcessStateChanged(processData) { 479 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 480 } 481}; 482let bundleNameList = ['bundleName1', 'bundleName2']; 483try { 484 observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 485 console.log(`[appManager] observerCode: ${observerId}`); 486} catch (paramError) { 487 console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `); 488} 489 490// 2. Deregister the application state observer. 491function unregisterApplicationStateObserverCallback(err) { 492 if (err.code !== 0) { 493 console.log('unregisterApplicationStateObserverCallback faile, err: ' + JSON.stringify(err)); 494 } else { 495 console.log('unregisterApplicationStateObserverCallback success.'); 496 } 497} 498try { 499 appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback); 500} catch (paramError) { 501 console.log('error: ' + paramError.code + ', ' + paramError.message); 502} 503``` 504 505## appManager.off 506 507off(type: 'applicationState', observerId: number): Promise\<void>; 508 509Deregisters the application state observer. This API uses an asynchronous callback to return the result. 510 511**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 512 513**System capability**: SystemCapability.Ability.AbilityRuntime.Core 514 515**System API**: This is a system API and cannot be called by third-party applications. 516 517**Parameters** 518 519| Name| Type| Mandatory| Description| 520| -------- | -------- | -------- | -------- | 521| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 522| observerId | number | Yes| Digital code of the observer.| 523 524**Return value** 525 526| Type| Description| 527| -------- | -------- | 528| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 529 530**Error codes** 531 532| ID| Error Message| 533| ------- | -------- | 534| 16000050 | Internal error. | 535 536For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 537 538**Example** 539 540```ts 541import appManager from '@ohos.app.ability.appManager'; 542 543let observerId = 0; 544 545// 1. Register an application state observer. 546let applicationStateObserver = { 547 onForegroundApplicationChanged(appStateData) { 548 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 549 }, 550 onAbilityStateChanged(abilityStateData) { 551 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 552 }, 553 onProcessCreated(processData) { 554 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 555 }, 556 onProcessDied(processData) { 557 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 558 }, 559 onProcessStateChanged(processData) { 560 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 561 } 562}; 563let bundleNameList = ['bundleName1', 'bundleName2']; 564try { 565 observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 566 console.log(`[appManager] observerCode: ${observerId}`); 567} catch (paramError) { 568 console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `); 569} 570 571// 2. Deregister the application state observer. 572try { 573 appManager.off('applicationState', observerId).then((data) => { 574 console.log('unregisterApplicationStateObserver success, data: ' + JSON.stringify(data)); 575 }).catch((err) => { 576 console.log('unregisterApplicationStateObserver faile, err: ' + JSON.stringify(err)); 577 }); 578} catch (paramError) { 579 console.log('error: ' + paramError.code + ', ' + paramError.message); 580} 581``` 582 583## appManager.getForegroundApplications 584 585getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void; 586 587Obtains 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). 588 589**Required permissions**: ohos.permission.GET_RUNNING_INFO 590 591**System capability**: SystemCapability.Ability.AbilityRuntime.Core 592 593**System API**: This is a system API and cannot be called by third-party applications. 594 595**Error codes** 596 597| ID| Error Message| 598| ------- | -------- | 599| 16000050 | Internal error. | 600 601For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 602 603**Parameters** 604 605| Name| Type| Mandatory| Description| 606| -------- | -------- | -------- | -------- | 607| 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.| 608 609**Example** 610 611```ts 612import appManager from '@ohos.app.ability.appManager'; 613 614function getForegroundApplicationsCallback(err, data) { 615 if (err.code !== 0) { 616 console.log('getForegroundApplicationsCallback fail, err: ' + JSON.stringify(err)); 617 } else { 618 console.log('getForegroundApplicationsCallback success, data: ' + JSON.stringify(data)); 619 } 620} 621try { 622 appManager.getForegroundApplications(getForegroundApplicationsCallback); 623} catch (paramError) { 624 console.log('error: ' + paramError.code + ', ' + paramError.message); 625} 626``` 627 628## appManager.getForegroundApplications 629 630getForegroundApplications(): Promise\<Array\<AppStateData>>; 631 632Obtains 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). 633 634**Required permissions**: ohos.permission.GET_RUNNING_INFO 635 636**System capability**: SystemCapability.Ability.AbilityRuntime.Core 637 638**System API**: This is a system API and cannot be called by third-party applications. 639 640**Return value** 641 642| Type| Description| 643| -------- | -------- | 644| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Promise used to return an array holding the application state data| 645 646**Error codes** 647 648| ID| Error Message| 649| ------- | -------- | 650| 16000050 | Internal error. | 651 652For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 653 654**Example** 655 656```ts 657import appManager from '@ohos.app.ability.appManager'; 658 659appManager.getForegroundApplications().then((data) => { 660 console.log('getForegroundApplications success, data: ' + JSON.stringify(data)); 661}).catch((err) => { 662 console.log('getForegroundApplications fail, err: ' + JSON.stringify(err)); 663}); 664``` 665 666## appManager.killProcessWithAccount 667 668killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\> 669 670Kills a process by bundle name and account ID. This API uses a promise to return the result. 671 672**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES 673 674**System capability**: SystemCapability.Ability.AbilityRuntime.Core 675 676**System API**: This is a system API and cannot be called by third-party applications. 677 678**Parameters** 679 680| Name| Type| Mandatory| Description| 681| -------- | -------- | -------- | -------- | 682| bundleName | string | Yes| Bundle name.| 683| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).| 684 685**Error codes** 686 687| ID| Error Message| 688| ------- | -------- | 689| 16000050 | Internal error. | 690 691For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 692 693**Example** 694 695```ts 696import appManager from '@ohos.app.ability.appManager'; 697 698let bundleName = 'bundleName'; 699let accountId = 0; 700try { 701 appManager.killProcessWithAccount(bundleName, accountId).then(() => { 702 console.log('killProcessWithAccount success'); 703 }).catch((err) => { 704 console.error('killProcessWithAccount fail, err: ' + JSON.stringify(err)); 705 }); 706} catch (paramError) { 707 console.error('error: ' + paramError.code + ', ' + paramError.message); 708} 709``` 710 711 712## appManager.killProcessWithAccount 713 714killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void 715 716Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result. 717 718**System capability**: SystemCapability.Ability.AbilityRuntime.Core 719 720**System API**: This is a system API and cannot be called by third-party applications. 721 722**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES 723 724**Parameters** 725 726 | Name| Type| Mandatory| Description| 727 | -------- | -------- | -------- | -------- | 728 | bundleName | string | Yes| Bundle name.| 729 | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).| 730 | callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 731 732**Error codes** 733 734| ID| Error Message| 735| ------- | -------- | 736| 16000050 | Internal error. | 737 738For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 739 740**Example** 741 742```ts 743import appManager from '@ohos.app.ability.appManager'; 744 745let bundleName = 'bundleName'; 746let accountId = 0; 747function killProcessWithAccountCallback(err, data) { 748 if (err.code !== 0) { 749 console.log('killProcessWithAccountCallback fail, err: ' + JSON.stringify(err)); 750 } else { 751 console.log('killProcessWithAccountCallback success.'); 752 } 753} 754appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); 755``` 756 757## appManager.killProcessesByBundleName 758 759killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>); 760 761Kills a process by bundle name. This API uses an asynchronous callback to return the result. 762 763**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 764 765**System capability**: SystemCapability.Ability.AbilityRuntime.Core 766 767**System API**: This is a system API and cannot be called by third-party applications. 768 769**Parameters** 770 771| Name| Type| Mandatory| Description| 772| -------- | -------- | -------- | -------- | 773| bundleName | string | Yes| Bundle name.| 774| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 775 776**Error codes** 777 778| ID| Error Message| 779| ------- | -------- | 780| 16000050 | Internal error. | 781 782For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 783 784**Example** 785 786```ts 787import appManager from '@ohos.app.ability.appManager'; 788 789let bundleName = 'bundleName'; 790function killProcessesByBundleNameCallback(err, data) { 791 if (err.code !== 0) { 792 console.log('killProcessesByBundleNameCallback fail, err: ' + JSON.stringify(err)); 793 } else { 794 console.log('killProcessesByBundleNameCallback success.'); 795 } 796} 797try { 798 appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); 799} catch (paramError) { 800 console.log('error: ' + paramError.code + ', ' + paramError.message); 801} 802``` 803 804## appManager.killProcessesByBundleName 805 806killProcessesByBundleName(bundleName: string): Promise\<void>; 807 808Kills a process by bundle name. This API uses a promise to return the result. 809 810**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 811 812**System capability**: SystemCapability.Ability.AbilityRuntime.Core 813 814**System API**: This is a system API and cannot be called by third-party applications. 815 816**Parameters** 817 818| Name| Type| Mandatory| Description| 819| -------- | -------- | -------- | -------- | 820| bundleName | string | Yes| Bundle name.| 821 822**Return value** 823 824| Type| Description| 825| -------- | -------- | 826| Promise\<void> | Promise used to return the result.| 827 828**Error codes** 829 830| ID| Error Message| 831| ------- | -------- | 832| 16000050 | Internal error. | 833 834For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 835 836**Example** 837 838```ts 839import appManager from '@ohos.app.ability.appManager'; 840 841let bundleName = 'bundleName'; 842try { 843 appManager.killProcessesByBundleName(bundleName).then((data) => { 844 console.log('killProcessesByBundleName success.'); 845 }).catch((err) => { 846 console.log('killProcessesByBundleName fail, err: ' + JSON.stringify(err)); 847 }); 848} catch (paramError) { 849 console.log('error: ' + paramError.code + ', ' + paramError.message); 850} 851``` 852 853## appManager.clearUpApplicationData 854 855clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>); 856 857Clears application data by bundle name. This API uses an asynchronous callback to return the result. 858 859**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 860 861**System capability**: SystemCapability.Ability.AbilityRuntime.Core 862 863**System API**: This is a system API and cannot be called by third-party applications. 864 865**Parameters** 866 867| Name| Type| Mandatory| Description| 868| -------- | -------- | -------- | -------- | 869| bundleName | string | Yes| Bundle name.| 870| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 871 872**Error codes** 873 874| ID| Error Message| 875| ------- | -------- | 876| 16000050 | Internal error. | 877 878For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 879 880**Example** 881 882```ts 883import appManager from '@ohos.app.ability.appManager'; 884 885let bundleName = 'bundleName'; 886function clearUpApplicationDataCallback(err, data) { 887 if (err) { 888 console.log('clearUpApplicationDataCallback fail, err: ' + JSON.stringify(err)); 889 } else { 890 console.log('clearUpApplicationDataCallback success.'); 891 } 892} 893try { 894 appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); 895} catch (paramError) { 896 console.log('error: ' + paramError.code + ', ' + paramError.message); 897} 898``` 899 900## appManager.clearUpApplicationData 901 902clearUpApplicationData(bundleName: string): Promise\<void>; 903 904Clears application data by bundle name. This API uses a promise to return the result. 905 906**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 907 908**System capability**: SystemCapability.Ability.AbilityRuntime.Core 909 910**System API**: This is a system API and cannot be called by third-party applications. 911 912**Parameters** 913 914| Name| Type| Mandatory| Description| 915| -------- | -------- | -------- | -------- | 916| bundleName | string | Yes| Bundle name.| 917 918**Return value** 919 920| Type| Description| 921| -------- | -------- | 922| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 923 924**Error codes** 925 926| ID| Error Message| 927| ------- | -------- | 928| 16000050 | Internal error. | 929 930For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 931 932**Example** 933 934```ts 935import appManager from '@ohos.app.ability.appManager'; 936 937let bundleName = 'bundleName'; 938try { 939 appManager.clearUpApplicationData(bundleName).then((data) => { 940 console.log('clearUpApplicationData success.'); 941 }).catch((err) => { 942 console.log('clearUpApplicationData fail, err: ' + JSON.stringify(err)); 943 }); 944} catch (paramError) { 945 console.log('error: ' + paramError.code + ', ' + paramError.message); 946} 947``` 948 949## ApplicationState 950 951Enumerates the application states. This enum can be used together with [AbilityStateData](js-apis-inner-application-appStateData.md) to return the application state. 952 953**System capability**: SystemCapability.Ability.AbilityRuntime.Core 954 955**System API**: This is a system API and cannot be called by third-party applications. 956 957| Name | Value | Description | 958| -------------------- | --- | --------------------------------- | 959| STATE_CREATE | 1 | State indicating that the application is being created. | 960| STATE_FOREGROUND | 2 | State indicating that the application is running in the foreground. | 961| STATE_ACTIVE | 3 | State indicating that the application is active. | 962| STATE_BACKGROUND | 4 | State indicating that the application is running in the background. | 963| STATE_DESTROY | 5 | State indicating that the application is destroyed. | 964 965## ProcessState 966 967Enumerates the process states. This enum can be used together with [ProcessData](js-apis-inner-application-processData.md) to return the process state. 968 969**System capability**: SystemCapability.Ability.AbilityRuntime.Core 970 971**System API**: This is a system API and cannot be called by third-party applications. 972 973| Name | Value | Description | 974| -------------------- | --- | --------------------------------- | 975| STATE_CREATE | 1 | State indicating that the process is being created. | 976| STATE_FOREGROUND | 2 | State indicating that the process is running in the foreground. | 977| STATE_ACTIVE | 3 | State indicating that the process is active. | 978| STATE_BACKGROUND | 4 | State indicating that the process is running in the background. | 979| STATE_DESTROY | 5 | State indicating that the process is destroyed. | 980