1# @ohos.app.ability.appManager (appManager) (System API) 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> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.app.ability.appManager (appManager)](js-apis-app-ability-appManager.md). 10 11## Modules to Import 12 13```ts 14import { appManager } from '@kit.AbilityKit'; 15``` 16 17## appManager.PreloadMode<sup>12+</sup> 18 19Enumerates the modes used for preloading an application process. 20 21**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22 23**System API**: This is a system API. 24 25**Model restriction**: This API can be used only in the stage model. 26 27| Name | Value | Description | 28| ----------- | --- | --------------------------- | 29| PRESS_DOWN | 0 | The application process is preloaded when the application icon is pressed.| 30 31## appManager.isSharedBundleRunning<sup>10+</sup> 32 33isSharedBundleRunning(bundleName: string, versionCode: number): Promise\<boolean> 34 35Checks whether the shared library is in use. This API uses a promise to return the result. 36 37**Required permissions**: ohos.permission.GET_RUNNING_INFO 38 39**System capability**: SystemCapability.Ability.AbilityRuntime.Core 40 41**System API**: This is a system API. 42 43**Parameters** 44 45| Name | Type | Mandatory | Description | 46| --------- | ---------------------------------------- | ---- | -------------- | 47| bundleName | string | Yes | Bundle name of the shared library.| 48| versionCode | number | Yes | Version number of the shared library. | 49 50**Return value** 51 52| Type| Description| 53| -------- | -------- | 54| Promise\<boolean> | Promise used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.| 55 56**Error codes** 57 58For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 59 60| ID| Error Message| 61| ------- | -------- | 62| 201 | Permission denied. | 63| 202 | Not System App. Interface caller is not a system app. | 64| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 65| 16000050 | Internal error. | 66 67**Example** 68 69```ts 70import { appManager } from '@kit.AbilityKit'; 71import { BusinessError } from '@kit.BasicServicesKit'; 72 73const bundleName = "this is a bundleName"; 74const versionCode = 1; 75 76appManager.isSharedBundleRunning(bundleName, versionCode).then((data) => { 77 console.log(`The shared bundle running is: ${JSON.stringify(data)}`); 78}).catch((error: BusinessError) => { 79 console.error(`error: ${JSON.stringify(error)}`); 80}); 81``` 82 83## appManager.isSharedBundleRunning<sup>10+</sup> 84 85isSharedBundleRunning(bundleName: string, versionCode: number, callback: AsyncCallback\<boolean>): void 86 87Checks whether the shared library is in use. This API uses an asynchronous callback to return the result. 88 89**Required permissions**: ohos.permission.GET_RUNNING_INFO 90 91**System capability**: SystemCapability.Ability.AbilityRuntime.Core 92 93**System API**: This is a system API. 94 95**Parameters** 96 97| Name | Type | Mandatory | Description | 98| --------- | ---------------------------------------- | ---- | -------------- | 99| bundleName | string | Yes | Bundle name of the shared library.| 100| versionCode | number | Yes | Version number of the shared library. | 101| callback | AsyncCallback\<boolean>> | Yes | Callback used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.| 102 103**Error codes** 104 105For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 106 107| ID| Error Message| 108| ------- | -------- | 109| 201 | Permission denied. | 110| 202 | Not System App. Interface caller is not a system app. | 111| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 112| 16000050 | Internal error. | 113 114**Example** 115 116```ts 117import { appManager } from '@kit.AbilityKit'; 118 119const bundleName = "this is a bundleName"; 120const versionCode = 1; 121 122appManager.isSharedBundleRunning(bundleName, versionCode, (err, data) => { 123 if (err) { 124 console.error(`err: ${JSON.stringify(err)}`); 125 } else { 126 console.log(`The shared bundle running is: ${JSON.stringify(data)}`); 127 } 128}); 129``` 130 131## appManager.on('applicationState') 132 133on(type: 'applicationState', observer: ApplicationStateObserver): number 134 135Registers an observer to listen for the state changes of all applications. 136 137**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 138 139**System capability**: SystemCapability.Ability.AbilityRuntime.Core 140 141**System API**: This is a system API. 142 143**Parameters** 144 145| Name| Type| Mandatory| Description| 146| -------- | -------- | -------- | -------- | 147| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 148| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver-sys.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 149 150**Return value** 151 152| Type| Description| 153| --- | --- | 154| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 155 156**Error codes** 157 158For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 159 160| ID| Error Message| 161| ------- | -------- | 162| 201 | Permission denied. | 163| 202 | Not System App. Interface caller is not a system app. | 164| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 165| 16000050 | Internal error. | 166 167**Example** 168 169```ts 170import { appManager } from '@kit.AbilityKit'; 171import { BusinessError } from '@kit.BasicServicesKit'; 172 173let applicationStateObserver: appManager.ApplicationStateObserver = { 174 onForegroundApplicationChanged(appStateData) { 175 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 176 }, 177 onAbilityStateChanged(abilityStateData) { 178 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 179 }, 180 onProcessCreated(processData) { 181 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 182 }, 183 onProcessDied(processData) { 184 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 185 }, 186 onProcessStateChanged(processData) { 187 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 188 }, 189 onAppStarted(appStateData) { 190 console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 191 }, 192 onAppStopped(appStateData) { 193 console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 194 } 195}; 196 197try { 198 const observerId = appManager.on('applicationState', applicationStateObserver); 199 console.log(`[appManager] observerCode: ${observerId}`); 200} catch (paramError) { 201 let code = (paramError as BusinessError).code; 202 let message = (paramError as BusinessError).message; 203 console.error(`[appManager] error: ${code}, ${message}`); 204} 205``` 206 207## appManager.on('applicationState') 208 209on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number 210 211Registers an observer to listen for the state changes of a specified application. 212 213**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 214 215**System capability**: SystemCapability.Ability.AbilityRuntime.Core 216 217**System API**: This is a system API. 218 219**Parameters** 220 221| Name| Type| Mandatory| Description| 222| -------- | -------- | -------- | -------- | 223| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 224| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver-sys.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 225| bundleNameList | `Array<string>` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.| 226 227**Return value** 228 229| Type| Description| 230| --- | --- | 231| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 232 233**Error codes** 234 235For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 236 237| ID| Error Message| 238| ------- | -------- | 239| 201 | Permission denied. | 240| 202 | Not System App. Interface caller is not a system app. | 241| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 242| 16000050 | Internal error. | 243 244**Example** 245 246```ts 247import { appManager } from '@kit.AbilityKit'; 248import { BusinessError } from '@kit.BasicServicesKit'; 249 250let applicationStateObserver: appManager.ApplicationStateObserver = { 251 onForegroundApplicationChanged(appStateData) { 252 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 253 }, 254 onAbilityStateChanged(abilityStateData) { 255 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 256 }, 257 onProcessCreated(processData) { 258 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 259 }, 260 onProcessDied(processData) { 261 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 262 }, 263 onProcessStateChanged(processData) { 264 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 265 }, 266 onAppStarted(appStateData) { 267 console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 268 }, 269 onAppStopped(appStateData) { 270 console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 271 } 272}; 273 274let bundleNameList = ['bundleName1', 'bundleName2']; 275 276try { 277 const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 278 console.log(`[appManager] observerCode: ${observerId}`); 279} catch (paramError) { 280 let code = (paramError as BusinessError).code; 281 let message = (paramError as BusinessError).message; 282 console.error(`[appManager] error: ${code}, ${message}`); 283} 284``` 285 286## appManager.on('appForegroundState')<sup>11+</sup> 287 288on(type: 'appForegroundState', observer: AppForegroundStateObserver): void 289 290Registers an observer to listen for application start or exit events. The observer can be used by a system application to observe the start or event events of all applications. 291 292**System API**: This is a system API. 293 294**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 295 296**System capability**: SystemCapability.Ability.AbilityRuntime.Core 297 298**Parameters** 299 300| Name| Type| Mandatory| Description| 301| -------- | -------- | -------- | -------- | 302| type | string | Yes| Event type. It is fixed at **'appForegroundState'**.| 303| observer | [AppForegroundStateObserver](js-apis-inner-application-appForegroundStateObserver-sys.md) | Yes| Observer used to listen for application start or exit events.| 304 305**Error codes** 306 307For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 308 309| ID| Error Message| 310| ------- | -------- | 311| 201 | Permission denied. | 312| 202 | Not System App. Interface caller is not a system app. | 313| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 314| 16000050 | Internal error. | 315 316**Example** 317 318```ts 319import { appManager } from '@kit.AbilityKit'; 320import { BusinessError } from '@kit.BasicServicesKit'; 321 322let observer: appManager.AppForegroundStateObserver = { 323 onAppStateChanged(appStateData) { 324 console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`); 325 }, 326}; 327 328try { 329 appManager.on('appForegroundState', observer); 330} catch (paramError) { 331 let code = (paramError as BusinessError).code; 332 let message = (paramError as BusinessError).message; 333 console.error(`[appManager] error: ${code}, ${message}`); 334} 335``` 336 337## appManager.on('abilityFirstFrameState')<sup>12+</sup> 338 339on(type: 'abilityFirstFrameState', observer: AbilityFirstFrameStateObserver, bundleName?: string): void 340 341Registers an observer to listen for the complete of the first frame rendering of a given ability. 342 343**System API**: This is a system API. 344 345**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 346 347**System capability**: SystemCapability.Ability.AbilityRuntime.Core 348 349**Parameters** 350 351| Name | Type | Mandatory| Description | 352| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 353| type | string | Yes | Event type. It is fixed at **'abilityFirstFrameState'**. | 354| observer | [AbilityFirstFrameStateObserver](js-apis-inner-application-abilityFirstFrameStateObserver-sys.md) | Yes | Observer used to listen for the complete of the first frame rendering of the ability. | 355| bundleName | string | No | Bundle name of the ability to be listened for. If this parameter is left blank, the event is listened for all applications.| 356 357**Error codes** 358 359For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 360 361| ID| Error Message| 362| ------- | -------- | 363| 201 | Permission denied. | 364| 202 | Not System App. Interface caller is not a system app. | 365| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 366| 16000050 | Internal error. | 367 368**Example** 369 370```ts 371import { appManager } from '@kit.AbilityKit'; 372import { BusinessError } from '@kit.BasicServicesKit'; 373 374let abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = { 375 onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) { 376 console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData)); 377 } 378}; 379 380try { 381 appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); 382} catch (e) { 383 let code = (e as BusinessError).code; 384 let message = (e as BusinessError).message; 385 console.error(`[appManager] error: ${code}, ${message}`); 386} 387``` 388 389## appManager.off('applicationState') 390 391off(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>): void 392 393Deregisters the application state observer. This API uses an asynchronous callback to return the result. 394 395**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 396 397**System capability**: SystemCapability.Ability.AbilityRuntime.Core 398 399**System API**: This is a system API. 400 401**Parameters** 402 403| Name| Type| Mandatory| Description| 404| -------- | -------- | -------- | -------- | 405| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 406| observerId | number | Yes| Digital code of the observer.| 407| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 408 409**Error codes** 410 411For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 412 413| ID| Error Message| 414| ------- | -------- | 415| 201 | Permission denied. | 416| 202 | Not System App. Interface caller is not a system app. | 417| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 418| 16000050 | Internal error. | 419 420**Example** 421 422```ts 423import { appManager } from '@kit.AbilityKit'; 424import { BusinessError } from '@kit.BasicServicesKit'; 425 426let observerId = 0; 427 428let applicationStateObserver: appManager.ApplicationStateObserver = { 429 onForegroundApplicationChanged(appStateData) { 430 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 431 }, 432 onAbilityStateChanged(abilityStateData) { 433 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 434 }, 435 onProcessCreated(processData) { 436 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 437 }, 438 onProcessDied(processData) { 439 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 440 }, 441 onProcessStateChanged(processData) { 442 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 443 }, 444 onAppStarted(appStateData) { 445 console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 446 }, 447 onAppStopped(appStateData) { 448 console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 449 } 450}; 451let bundleNameList = ['bundleName1', 'bundleName2']; 452 453try { 454 observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 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// 2. Deregister the application state observer. 463function unregisterApplicationStateObserverCallback(err: BusinessError) { 464 if (err) { 465 console.error(`unregisterApplicationStateObserverCallback fail, err: ${JSON.stringify(err)}`); 466 } else { 467 console.log('unregisterApplicationStateObserverCallback success.'); 468 } 469} 470 471try { 472 appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback); 473} catch (paramError) { 474 let code = (paramError as BusinessError).code; 475 let message = (paramError as BusinessError).message; 476 console.error(`[appManager] error: ${code}, ${message}`); 477} 478``` 479 480## appManager.off('applicationState') 481 482off(type: 'applicationState', observerId: number): Promise\<void> 483 484Deregisters the application state observer. This API uses an asynchronous callback to return the result. 485 486**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 487 488**System capability**: SystemCapability.Ability.AbilityRuntime.Core 489 490**System API**: This is a system API. 491 492**Parameters** 493 494| Name| Type| Mandatory| Description| 495| -------- | -------- | -------- | -------- | 496| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 497| observerId | number | Yes| Digital code of the observer.| 498 499**Return value** 500 501| Type| Description| 502| -------- | -------- | 503| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 504 505**Error codes** 506 507For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 508 509| ID| Error Message| 510| ------- | -------- | 511| 201 | Permission denied. | 512| 202 | Not System App. Interface caller is not a system app. | 513| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 514| 16000050 | Internal error. | 515 516**Example** 517 518```ts 519import { appManager } from '@kit.AbilityKit'; 520import { BusinessError } from '@kit.BasicServicesKit'; 521 522let observerId = 0; 523 524// 1. Register an application state observer. 525let applicationStateObserver: appManager.ApplicationStateObserver = { 526 onForegroundApplicationChanged(appStateData) { 527 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 528 }, 529 onAbilityStateChanged(abilityStateData) { 530 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 531 }, 532 onProcessCreated(processData) { 533 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 534 }, 535 onProcessDied(processData) { 536 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 537 }, 538 onProcessStateChanged(processData) { 539 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 540 }, 541 onAppStarted(appStateData) { 542 console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 543 }, 544 onAppStopped(appStateData) { 545 console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 546 } 547}; 548let bundleNameList = ['bundleName1', 'bundleName2']; 549 550try { 551 observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 552} catch (paramError) { 553 let code = (paramError as BusinessError).code; 554 let message = (paramError as BusinessError).message; 555 console.error(`[appManager] error: ${code}, ${message}`); 556} 557 558// 2. Deregister the application state observer. 559try { 560 appManager.off('applicationState', observerId).then((data) => { 561 console.log(`unregisterApplicationStateObserver success, data: ${JSON.stringify(data)}`); 562 }).catch((err: BusinessError) => { 563 console.error(`unregisterApplicationStateObserver fail, err: ${JSON.stringify(err)}`); 564 }); 565} catch (paramError) { 566 let code = (paramError as BusinessError).code; 567 let message = (paramError as BusinessError).message; 568 console.error(`[appManager] error: ${code}, ${message}`); 569} 570``` 571 572## appManager.off('appForegroundState')<sup>11+</sup> 573 574off(type: 'appForegroundState', observer?: AppForegroundStateObserver): void 575 576Deregisters the observer used to listen for application start or exit events. 577 578**System API**: This is a system API. 579 580**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 581 582**System capability**: SystemCapability.Ability.AbilityRuntime.Core 583 584**Parameters** 585 586| Name| Type| Mandatory| Description| 587| -------- | -------- | -------- | -------- | 588| type | string | Yes| Event type. It is fixed at **'appForegroundState'**.| 589| observer | [AppForegroundStateObserver](js-apis-inner-application-appForegroundStateObserver-sys.md) | No| Observer used to listen for application start or exit events.| 590 591**Error codes** 592 593For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 594 595| ID| Error Message| 596| ------- | -------- | 597| 201 | Permission denied. | 598| 202 | Not System App. Interface caller is not a system app. | 599| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 600| 16000050 | Internal error. | 601 602**Example** 603 604```ts 605import { appManager } from '@kit.AbilityKit'; 606import { BusinessError } from '@kit.BasicServicesKit'; 607 608let observer_: appManager.AppForegroundStateObserver | undefined; 609// 1. Register an observer to listen for application start or exit events. 610let observer: appManager.AppForegroundStateObserver = { 611 onAppStateChanged(appStateData: appManager.AppStateData) { 612 console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`); 613 }, 614}; 615 616try { 617 appManager.on('appForegroundState', observer); 618 // Save the observer object. 619 observer_ = observer; 620} catch (paramError) { 621 let code = (paramError as BusinessError).code; 622 let message = (paramError as BusinessError).message; 623 console.error(`[appManager] error: ${code}, ${message}`); 624} 625 626// 2. Deregister the observer. 627try { 628 appManager.off('appForegroundState', observer_); 629} catch (paramError) { 630 let code = (paramError as BusinessError).code; 631 let message = (paramError as BusinessError).message; 632 console.error(`[appManager] error: ${code}, ${message}`); 633} 634``` 635 636## appManager.off('abilityFirstFrameState')<sup>12+</sup> 637 638off(type: 'abilityFirstFrameState', observer?: AbilityFirstFrameStateObserver): void 639 640Deregisters the observer used to listen for the complete of the first frame rendering of a given ability. 641 642**System API**: This is a system API. 643 644**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 645 646**System capability**: SystemCapability.Ability.AbilityRuntime.Core 647 648**Parameters** 649 650| Name | Type | Mandatory| Description | 651| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 652| type | string | Yes | Event type. It is fixed at **'abilityFirstFrameState'**. | 653| observer | [AbilityFirstFrameStateObserver](js-apis-inner-application-abilityFirstFrameStateObserver-sys.md) | No | Callback used for deregistration. If this parameter is left blank, all subscriptions to the specified event are canceled.| 654 655**Error codes** 656 657For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 658 659| ID| Error Message| 660| ------- | -------- | 661| 201 | Permission denied. | 662| 202 | Not System App. Interface caller is not a system app. | 663| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 664| 16000050 | Internal error. | 665 666**Example** 667 668```ts 669import { appManager } from '@kit.AbilityKit'; 670import { BusinessError } from '@kit.BasicServicesKit'; 671 672let abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = { 673 onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) { 674 console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData)); 675 } 676}; 677 678try { 679 appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); 680} catch (e) { 681 let code = (e as BusinessError).code; 682 let message = (e as BusinessError).message; 683 console.error(`[appManager] error: ${code}, ${message}`); 684} 685 686try { 687 appManager.off('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); 688} catch (e) { 689 let code = (e as BusinessError).code; 690 let message = (e as BusinessError).message; 691 console.error(`[appManager] error: ${code}, ${message}`); 692} 693``` 694 695## appManager.getForegroundApplications 696 697getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void 698 699Obtains 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-sys.md). 700 701**Required permissions**: ohos.permission.GET_RUNNING_INFO 702 703**System capability**: SystemCapability.Ability.AbilityRuntime.Core 704 705**System API**: This is a system API. 706 707**Parameters** 708 709| Name| Type| Mandatory| Description| 710| -------- | -------- | -------- | -------- | 711| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData-sys.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.| 712 713**Error codes** 714 715For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 716 717| ID| Error Message| 718| ------- | -------- | 719| 201 | Permission denied. | 720| 202 | Not System App. Interface caller is not a system app. | 721| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 722| 16000050 | Internal error. | 723 724**Example** 725 726```ts 727import { appManager } from '@kit.AbilityKit'; 728import { BusinessError } from '@kit.BasicServicesKit'; 729 730function getForegroundApplicationsCallback(err: BusinessError, data: Array<appManager.AppStateData>) { 731 if (err) { 732 console.error(`getForegroundApplicationsCallback fail, err: ${JSON.stringify(err)}`); 733 } else { 734 console.log(`getForegroundApplicationsCallback success, data: ${JSON.stringify(data)}`); 735 } 736} 737 738try { 739 appManager.getForegroundApplications(getForegroundApplicationsCallback); 740} catch (paramError) { 741 let code = (paramError as BusinessError).code; 742 let message = (paramError as BusinessError).message; 743 console.error(`[appManager] error: ${code}, ${message}`); 744} 745``` 746 747## appManager.getForegroundApplications 748 749getForegroundApplications(): Promise\<Array\<AppStateData>> 750 751Obtains 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-sys.md). 752 753**Required permissions**: ohos.permission.GET_RUNNING_INFO 754 755**System capability**: SystemCapability.Ability.AbilityRuntime.Core 756 757**System API**: This is a system API. 758 759**Return value** 760 761| Type| Description| 762| -------- | -------- | 763| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData-sys.md)>> | Promise used to return an array holding the application state data.| 764 765**Error codes** 766 767For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 768 769| ID| Error Message| 770| ------- | -------- | 771| 201 | Permission denied. | 772| 202 | Not System App. Interface caller is not a system app. | 773| 16000050 | Internal error. | 774 775**Example** 776 777```ts 778import { appManager } from '@kit.AbilityKit'; 779import { BusinessError } from '@kit.BasicServicesKit'; 780 781appManager.getForegroundApplications().then((data) => { 782 console.log(`getForegroundApplications success, data: ${JSON.stringify(data)}`); 783}).catch((err: BusinessError) => { 784 console.error(`getForegroundApplications fail, err: ${JSON.stringify(err)}`); 785}); 786``` 787 788## appManager.killProcessWithAccount 789 790killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\> 791 792Kills a process by bundle name and account ID. This API uses a promise to return the result. 793 794> **NOTE** 795> 796> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 797 798**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES, or ohos.permission.CLEAN_BACKGROUND_PROCESSES 799 800**System capability**: SystemCapability.Ability.AbilityRuntime.Core 801 802**System API**: This is a system API. 803 804**Parameters** 805 806| Name| Type| Mandatory| Description| 807| -------- | -------- | -------- | -------- | 808| bundleName | string | Yes| Bundle name.| 809| accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| 810 811**Return value** 812 813| Type | Description | 814| -------------- | --------------- | 815| Promise\<void> | Promise that returns no value.| 816 817**Error codes** 818 819For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 820 821| ID| Error Message| 822| ------- | -------- | 823| 201 | Permission denied. | 824| 202 | Not System App. Interface caller is not a system app. | 825| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 826| 16000050 | Internal error. | 827 828**Example** 829 830```ts 831import { appManager } from '@kit.AbilityKit'; 832import { BusinessError } from '@kit.BasicServicesKit'; 833 834let bundleName = 'bundleName'; 835let accountId = 0; 836 837try { 838 appManager.killProcessWithAccount(bundleName, accountId).then(() => { 839 console.log('killProcessWithAccount success'); 840 }).catch((err: BusinessError) => { 841 console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`); 842 }); 843} catch (paramError) { 844 let code = (paramError as BusinessError).code; 845 let message = (paramError as BusinessError).message; 846 console.error(`[appManager] error: ${code}, ${message}`); 847} 848``` 849 850## appManager.killProcessWithAccount<sup>13+</sup> 851 852killProcessWithAccount(bundleName: string, accountId: number, clearPageStack: boolean, appIndex?: number): Promise\<void\> 853 854Kills a process by bundle name and account ID. This API uses a promise to return the result. 855 856> **NOTE** 857> 858> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 859 860**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES 861 862**System capability**: SystemCapability.Ability.AbilityRuntime.Core 863 864**System API**: This is a system API. 865 866**Parameters** 867 868| Name| Type| Mandatory| Description| 869| -------- | -------- | -------- | -------- | 870| bundleName | string | Yes| Bundle name.| 871| accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| 872| clearPageStack | boolean | Yes| Whether to clear the page stack. The value **true** means to clear the page stack, and **false** means the opposite.| 873| appIndex | number | No| Index of an application clone.| 874 875**Return value** 876 877| Type | Description | 878| -------------- | --------------- | 879| Promise\<void> | Promise that returns no value.| 880 881**Error codes** 882 883For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 884 885| ID| Error Message| 886| ------- | -------- | 887| 201 | Permission denied. | 888| 202 | Not System App. Interface caller is not a system app. | 889| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 890| 16000050 | Internal error. | 891 892**Example** 893 894```ts 895import { appManager } from '@kit.AbilityKit'; 896import { BusinessError } from '@kit.BasicServicesKit'; 897 898let bundleName = 'bundleName'; 899let accountId = 0; 900let isClearPageStack = false; 901let appIndex = 1; 902 903try { 904 appManager.killProcessWithAccount(bundleName, accountId, isClearPageStack, appIndex).then(() => { 905 console.log('killProcessWithAccount success'); 906 }).catch((err: BusinessError) => { 907 console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`); 908 }); 909} catch (paramError) { 910 let code = (paramError as BusinessError).code; 911 let message = (paramError as BusinessError).message; 912 console.error(`[appManager] error: ${code}, ${message}`); 913} 914``` 915 916## appManager.killProcessWithAccount 917 918killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void 919 920Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result. 921 922> **NOTE** 923> 924> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 925 926**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES, or ohos.permission.CLEAN_BACKGROUND_PROCESSES 927 928**System capability**: SystemCapability.Ability.AbilityRuntime.Core 929 930**System API**: This is a system API. 931 932**Parameters** 933 934 | Name| Type| Mandatory| Description| 935 | -------- | -------- | -------- | -------- | 936 | bundleName | string | Yes| Bundle name.| 937 | accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| 938 | callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 939 940**Error codes** 941 942For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 943 944| ID| Error Message| 945| ------- | -------- | 946| 201 | Permission denied. | 947| 202 | Not System App. Interface caller is not a system app. | 948| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 949| 16000050 | Internal error. | 950 951**Example** 952 953```ts 954import { appManager } from '@kit.AbilityKit'; 955import { BusinessError } from '@kit.BasicServicesKit'; 956 957let bundleName = 'bundleName'; 958let accountId = 0; 959 960function killProcessWithAccountCallback(err: BusinessError) { 961 if (err) { 962 console.error(`killProcessWithAccountCallback fail, err: ${JSON.stringify(err)}`); 963 } else { 964 console.log('killProcessWithAccountCallback success.'); 965 } 966} 967 968appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); 969``` 970 971## appManager.killProcessesByBundleName 972 973killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>) 974 975Kills a process by bundle name. This API uses an asynchronous callback to return the result. 976 977**Required permissions**: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES 978 979**System capability**: SystemCapability.Ability.AbilityRuntime.Core 980 981**System API**: This is a system API. 982 983**Parameters** 984 985| Name| Type| Mandatory| Description| 986| -------- | -------- | -------- | -------- | 987| bundleName | string | Yes| Bundle name.| 988| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 989 990**Error codes** 991 992For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 993 994| ID| Error Message| 995| ------- | -------- | 996| 201 | Permission denied. | 997| 202 | Not System App. Interface caller is not a system app. | 998| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 999| 16000050 | Internal error. | 1000 1001**Example** 1002 1003```ts 1004import { appManager } from '@kit.AbilityKit'; 1005import { BusinessError } from '@kit.BasicServicesKit'; 1006 1007let bundleName = 'bundleName'; 1008 1009function killProcessesByBundleNameCallback(err: BusinessError) { 1010 if (err) { 1011 console.error(`killProcessesByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 1012 } else { 1013 console.log('killProcessesByBundleNameCallback success.'); 1014 } 1015} 1016 1017try { 1018 appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); 1019} catch (paramError) { 1020 let code = (paramError as BusinessError).code; 1021 let message = (paramError as BusinessError).message; 1022 console.error(`[appManager] error: ${code}, ${message}`); 1023} 1024``` 1025 1026## appManager.killProcessesByBundleName 1027 1028killProcessesByBundleName(bundleName: string): Promise\<void> 1029 1030Kills a process by bundle name. This API uses a promise to return the result. 1031 1032**Required permissions**: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES 1033 1034**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1035 1036**System API**: This is a system API. 1037 1038**Parameters** 1039 1040| Name| Type| Mandatory| Description| 1041| -------- | -------- | -------- | -------- | 1042| bundleName | string | Yes| Bundle name.| 1043 1044**Return value** 1045 1046| Type| Description| 1047| -------- | -------- | 1048| Promise\<void> | Promise that returns no value.| 1049 1050**Error codes** 1051 1052For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1053 1054| ID| Error Message| 1055| ------- | -------- | 1056| 201 | Permission denied. | 1057| 202 | Not System App. Interface caller is not a system app. | 1058| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1059| 16000050 | Internal error. | 1060 1061**Example** 1062 1063```ts 1064import { appManager } from '@kit.AbilityKit'; 1065import { BusinessError } from '@kit.BasicServicesKit'; 1066 1067let bundleName = 'bundleName'; 1068 1069try { 1070 appManager.killProcessesByBundleName(bundleName).then((data) => { 1071 console.log('killProcessesByBundleName success.'); 1072 }).catch((err: BusinessError) => { 1073 console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`); 1074 }); 1075} catch (paramError) { 1076 let code = (paramError as BusinessError).code; 1077 let message = (paramError as BusinessError).message; 1078 console.error(`[appManager] error: ${code}, ${message}`); 1079} 1080``` 1081 1082## appManager.killProcessesByBundleName<sup>13+</sup> 1083 1084killProcessesByBundleName(bundleName: string, clearPageStack: boolean, appIndex?: number): Promise\<void> 1085 1086Kills a process by bundle name. This API uses a promise to return the result. 1087 1088**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 1089 1090**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1091 1092**System API**: This is a system API. 1093 1094**Parameters** 1095 1096| Name| Type| Mandatory| Description| 1097| -------- | -------- | -------- | -------- | 1098| bundleName | string | Yes| Bundle name.| 1099| clearPageStack | boolean | Yes| Whether to clear the page stack. The value **true** means to clear the page stack, and **false** means the opposite.| 1100| appIndex | number | No| Index of an application clone.| 1101 1102**Return value** 1103 1104| Type| Description| 1105| -------- | -------- | 1106| Promise\<void> | Promise that returns no value.| 1107 1108**Error codes** 1109 1110For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1111 1112| ID| Error Message| 1113| ------- | -------- | 1114| 201 | Permission denied. | 1115| 202 | Not System App. Interface caller is not a system app. | 1116| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1117| 16000050 | Internal error. | 1118 1119**Example** 1120 1121```ts 1122import { appManager } from '@kit.AbilityKit'; 1123import { BusinessError } from '@kit.BasicServicesKit'; 1124 1125let bundleName = 'bundleName'; 1126let isClearPageStack = false; 1127let appIndex = 1; 1128 1129try { 1130 appManager.killProcessesByBundleName(bundleName, isClearPageStack, appIndex).then((data) => { 1131 console.log('killProcessesByBundleName success.'); 1132 }).catch((err: BusinessError) => { 1133 console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`); 1134 }); 1135} catch (paramError) { 1136 let code = (paramError as BusinessError).code; 1137 let message = (paramError as BusinessError).message; 1138 console.error(`[appManager] error: ${code}, ${message}`); 1139} 1140``` 1141 1142## appManager.clearUpApplicationData 1143 1144clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>) 1145 1146Clears application data by bundle name. This API uses an asynchronous callback to return the result. 1147 1148**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 1149 1150**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1151 1152**System API**: This is a system API. 1153 1154**Parameters** 1155 1156| Name| Type| Mandatory| Description| 1157| -------- | -------- | -------- | -------- | 1158| bundleName | string | Yes| Bundle name.| 1159| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 1160 1161**Error codes** 1162 1163For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1164 1165| ID| Error Message| 1166| ------- | -------- | 1167| 201 | Permission denied. | 1168| 202 | Not System App. Interface caller is not a system app. | 1169| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1170| 16000050 | Internal error. | 1171 1172**Example** 1173 1174```ts 1175import { appManager } from '@kit.AbilityKit'; 1176import { BusinessError } from '@kit.BasicServicesKit'; 1177 1178let bundleName = 'bundleName'; 1179 1180function clearUpApplicationDataCallback(err: BusinessError) { 1181 if (err) { 1182 console.error(`clearUpApplicationDataCallback fail, err: ${JSON.stringify(err)}`); 1183 } else { 1184 console.log('clearUpApplicationDataCallback success.'); 1185 } 1186} 1187 1188try { 1189 appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); 1190} catch (paramError) { 1191 let code = (paramError as BusinessError).code; 1192 let message = (paramError as BusinessError).message; 1193 console.error(`[appManager] error: ${code}, ${message}`); 1194} 1195``` 1196 1197## appManager.clearUpApplicationData 1198 1199clearUpApplicationData(bundleName: string): Promise\<void> 1200 1201Clears application data by bundle name. This API uses a promise to return the result. 1202 1203**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 1204 1205**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1206 1207**System API**: This is a system API. 1208 1209**Parameters** 1210 1211| Name| Type| Mandatory| Description| 1212| -------- | -------- | -------- | -------- | 1213| bundleName | string | Yes| Bundle name.| 1214 1215**Return value** 1216 1217| Type| Description| 1218| -------- | -------- | 1219| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 1220 1221**Error codes** 1222 1223For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1224 1225| ID| Error Message| 1226| ------- | -------- | 1227| 201 | Permission denied. | 1228| 202 | Not System App. Interface caller is not a system app. | 1229| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1230| 16000050 | Internal error. | 1231 1232**Example** 1233 1234```ts 1235import { appManager } from '@kit.AbilityKit'; 1236import { BusinessError } from '@kit.BasicServicesKit'; 1237 1238let bundleName = 'bundleName'; 1239 1240try { 1241 appManager.clearUpApplicationData(bundleName).then((data) => { 1242 console.log('clearUpApplicationData success.'); 1243 }).catch((err: BusinessError) => { 1244 console.error(`clearUpApplicationData fail, err: ${JSON.stringify(err)}`); 1245 }); 1246} catch (paramError) { 1247 let code = (paramError as BusinessError).code; 1248 let message = (paramError as BusinessError).message; 1249 console.error(`[appManager] error: ${code}, ${message}`); 1250} 1251``` 1252 1253## appManager.getProcessMemoryByPid<sup>10+</sup> 1254 1255getProcessMemoryByPid(pid: number, callback: AsyncCallback\<number>): void 1256 1257Obtains the memory size of a process. This API uses an asynchronous callback to return the result. 1258 1259**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1260 1261**System API**: This is a system API. 1262 1263**Parameters** 1264 1265| Name| Type| Mandatory| Description| 1266| -------- | -------- | -------- | -------- | 1267| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](#appmanagergetrunningprocessinfobybundlename10).| 1268| 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.| 1269 1270**Error codes** 1271 1272For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1273 1274| ID| Error Message| 1275| ------- | -------- | 1276| 202 | Not System App. Interface caller is not a system app. | 1277| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1278| 16000050 | Internal error. | 1279 1280**Example** 1281 1282```ts 1283import { appManager } from '@kit.AbilityKit'; 1284import { BusinessError } from '@kit.BasicServicesKit'; 1285 1286let pid = 0; 1287function getProcessMemoryByPidCallback(err: BusinessError, data: number) { 1288 if (err) { 1289 console.error(`getProcessMemoryByPidCallback fail, err: ${JSON.stringify(err)}`); 1290 } else { 1291 console.log('getProcessMemoryByPidCallback success.'); 1292 } 1293} 1294 1295try { 1296 appManager.getProcessMemoryByPid(pid, getProcessMemoryByPidCallback); 1297} catch (paramError) { 1298 let code = (paramError as BusinessError).code; 1299 let message = (paramError as BusinessError).message; 1300 console.error(`[appManager] error: ${code}, ${message}`); 1301} 1302``` 1303 1304## appManager.getProcessMemoryByPid<sup>10+</sup> 1305 1306getProcessMemoryByPid(pid: number): Promise\<number> 1307 1308Obtains the memory size of a process. This API uses a promise to return the result. 1309 1310**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1311 1312**System API**: This is a system API. 1313 1314**Parameters** 1315 1316| Name| Type| Mandatory| Description| 1317| -------- | -------- | -------- | -------- | 1318| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](#appmanagergetrunningprocessinfobybundlename10). | 1319 1320**Return value** 1321 1322| Type| Description| 1323| -------- | -------- | 1324| 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.| 1325 1326**Error codes** 1327 1328For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1329 1330| ID| Error Message| 1331| ------- | -------- | 1332| 202 | Not System App. Interface caller is not a system app. | 1333| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1334| 16000050 | Internal error. | 1335 1336**Example** 1337 1338```ts 1339import { appManager } from '@kit.AbilityKit'; 1340import { BusinessError } from '@kit.BasicServicesKit'; 1341 1342let pid = 0; 1343 1344try { 1345 appManager.getProcessMemoryByPid(pid).then((data) => { 1346 console.log('getProcessMemoryByPid success.'); 1347 }).catch((err: BusinessError) => { 1348 console.error(`getProcessMemoryByPid fail, err: ${JSON.stringify(err)}`); 1349 }); 1350} catch (paramError) { 1351 let code = (paramError as BusinessError).code; 1352 let message = (paramError as BusinessError).message; 1353 console.error(`[appManager] error: ${code}, ${message}`); 1354} 1355``` 1356 1357## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1358 1359getRunningProcessInfoByBundleName(bundleName: string, callback: AsyncCallback\<Array\<ProcessInformation>>): void 1360 1361Obtains information about the running processes by bundle name. This API uses an asynchronous callback to return the result. 1362 1363**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1364 1365**System API**: This is a system API. 1366 1367**Parameters** 1368 1369| Name| Type| Mandatory| Description| 1370| -------- | -------- | -------- | -------- | 1371| bundleName | string | Yes| Bundle name.| 1372| 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.| 1373 1374**Error codes** 1375 1376For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1377 1378| ID| Error Message| 1379| ------- | -------- | 1380| 202 | Not System App. Interface caller is not a system app. | 1381| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1382| 16000050 | Internal error. | 1383 1384**Example** 1385 1386```ts 1387import { appManager } from '@kit.AbilityKit'; 1388import { BusinessError } from '@kit.BasicServicesKit'; 1389 1390let bundleName = "bundleName"; 1391function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) { 1392 if (err) { 1393 console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 1394 } else { 1395 console.log('getRunningProcessInfoByBundleNameCallback success.'); 1396 } 1397} 1398 1399try { 1400 appManager.getRunningProcessInfoByBundleName(bundleName, getRunningProcessInfoByBundleNameCallback); 1401} catch (paramError) { 1402 let code = (paramError as BusinessError).code; 1403 let message = (paramError as BusinessError).message; 1404 console.error(`[appManager] error: ${code}, ${message}`); 1405} 1406``` 1407 1408## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1409 1410getRunningProcessInfoByBundleName(bundleName: string): Promise\<Array\<ProcessInformation>> 1411 1412Obtains information about the running processes by bundle name. This API uses a promise to return the result. 1413 1414**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1415 1416**System API**: This is a system API. 1417 1418**Parameters** 1419 1420| Name| Type| Mandatory| Description| 1421| -------- | -------- | -------- | -------- | 1422| bundleName | string | Yes| Bundle name.| 1423 1424**Return value** 1425 1426| Type| Description| 1427| -------- | -------- | 1428| 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.| 1429 1430**Error codes** 1431 1432For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1433 1434| ID| Error Message| 1435| ------- | -------- | 1436| 202 | Not System App. Interface caller is not a system app. | 1437| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1438| 16000050 | Internal error. | 1439 1440**Example** 1441 1442```ts 1443import { appManager } from '@kit.AbilityKit'; 1444import { BusinessError } from '@kit.BasicServicesKit'; 1445 1446let bundleName = "bundleName"; 1447 1448try { 1449 appManager.getRunningProcessInfoByBundleName(bundleName).then((data) => { 1450 console.log('getRunningProcessInfoByBundleName success.'); 1451 }).catch((err: BusinessError) => { 1452 console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`); 1453 }); 1454} catch (paramError) { 1455 let code = (paramError as BusinessError).code; 1456 let message = (paramError as BusinessError).message; 1457 console.error(`[appManager] error: ${code}, ${message}`); 1458} 1459``` 1460 1461## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1462 1463getRunningProcessInfoByBundleName(bundleName: string, userId: number, callback: AsyncCallback\<Array\<ProcessInformation>>): void 1464 1465Obtains information about the running processes by bundle name and user ID. This API uses an asynchronous callback to return the result. 1466 1467**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1468 1469**System API**: This is a system API. 1470 1471**Parameters** 1472 1473| Name| Type| Mandatory| Description| 1474| -------- | -------- | -------- | -------- | 1475| bundleName | string | Yes| Bundle name.| 1476| userId | number | Yes| User ID.| 1477| 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.| 1478 1479**Error codes** 1480 1481For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1482 1483| ID| Error Message| 1484| ------- | -------- | 1485| 202 | Not System App. Interface caller is not a system app. | 1486| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1487| 16000050 | Internal error. | 1488 1489**Example** 1490 1491```ts 1492import { appManager } from '@kit.AbilityKit'; 1493import { BusinessError } from '@kit.BasicServicesKit'; 1494 1495let bundleName = "bundleName"; 1496let userId = 0; 1497function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) { 1498 if (err) { 1499 console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 1500 } else { 1501 console.log('getRunningProcessInfoByBundleNameCallback success.'); 1502 } 1503} 1504 1505try { 1506 appManager.getRunningProcessInfoByBundleName(bundleName, userId, getRunningProcessInfoByBundleNameCallback); 1507} catch (paramError) { 1508 let code = (paramError as BusinessError).code; 1509 let message = (paramError as BusinessError).message; 1510 console.error(`[appManager] error: ${code}, ${message}`); 1511} 1512``` 1513 1514## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1515 1516getRunningProcessInfoByBundleName(bundleName: string, userId: number): Promise\<Array\<ProcessInformation>> 1517 1518Obtains information about the running processes by bundle name and user ID. This API uses a promise to return the result. 1519 1520**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1521 1522**System API**: This is a system API. 1523 1524**Parameters** 1525 1526| Name| Type| Mandatory| Description| 1527| -------- | -------- | -------- | -------- | 1528| bundleName | string | Yes| Bundle name.| 1529| userId | number | Yes| User ID.| 1530 1531**Return value** 1532 1533| Type| Description| 1534| -------- | -------- | 1535| 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.| 1536 1537**Error codes** 1538 1539For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1540 1541| ID| Error Message| 1542| ------- | -------- | 1543| 202 | Not System App. Interface caller is not a system app. | 1544| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1545| 16000050 | Internal error. | 1546 1547**Example** 1548 1549```ts 1550import { appManager } from '@kit.AbilityKit'; 1551import { BusinessError } from '@kit.BasicServicesKit'; 1552 1553let bundleName = "bundleName"; 1554let userId = 0; 1555 1556try { 1557 appManager.getRunningProcessInfoByBundleName(bundleName, userId).then((data) => { 1558 console.log('getRunningProcessInfoByBundleName success.'); 1559 }).catch((err: BusinessError) => { 1560 console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`); 1561 }); 1562} catch (paramError) { 1563 let code = (paramError as BusinessError).code; 1564 let message = (paramError as BusinessError).message; 1565 console.error(`[appManager] error: ${code}, ${message}`); 1566} 1567``` 1568 1569## appManager.isApplicationRunning<sup>11+</sup> 1570 1571isApplicationRunning(bundleName: string): Promise\<boolean> 1572 1573Checks whether an application is running. This API uses a promise to return the result. 1574 1575**System API**: This is a system API. 1576 1577**Required permissions**: ohos.permission.GET_RUNNING_INFO 1578 1579**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1580 1581**Parameters** 1582 1583| Name | Type | Mandatory | Description | 1584| --------- | ---------------------------------------- | ---- | -------------- | 1585| bundleName | string | Yes | Bundle name.| 1586 1587**Return value** 1588 1589| Type| Description| 1590| -------- | -------- | 1591| Promise\<boolean> | Promise used to return the result. The value **true** means that the application is running, and **false** means the opposite.| 1592 1593**Error codes** 1594 1595For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1596 1597| ID| Error Message| 1598| ------- | -------- | 1599| 201 | Permission denied. | 1600| 202 | Not System App. Interface caller is not a system app. | 1601| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1602| 16000050 | Internal error. | 1603 1604**Example** 1605 1606```ts 1607import { appManager } from '@kit.AbilityKit'; 1608import { BusinessError } from '@kit.BasicServicesKit'; 1609 1610let bundleName = "com.example.myapplication"; 1611 1612appManager.isApplicationRunning(bundleName).then((data) => { 1613 console.log(`The application running is: ${JSON.stringify(data)}`); 1614}).catch((error: BusinessError) => { 1615 console.error(`error: ${JSON.stringify(error)}`); 1616}); 1617``` 1618 1619## appManager.isApplicationRunning<sup>11+</sup> 1620 1621isApplicationRunning(bundleName: string, callback: AsyncCallback\<boolean>): void 1622 1623Checks whether an application is running. This API uses an asynchronous callback to return the result. 1624 1625**System API**: This is a system API. 1626 1627**Required permissions**: ohos.permission.GET_RUNNING_INFO 1628 1629**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1630 1631**Parameters** 1632 1633| Name | Type | Mandatory | Description | 1634| --------- | ---------------------------------------- | ---- | -------------- | 1635| bundleName | string | Yes | Bundle name of the shared library.| 1636| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. The value **true** means that the application is running, and **false** means the opposite.| 1637 1638**Error codes** 1639 1640For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1641 1642| ID| Error Message| 1643| ------- | -------- | 1644| 201 | Permission denied. | 1645| 202 | Not System App. Interface caller is not a system app. | 1646| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1647| 16000050 | Internal error. | 1648 1649**Example** 1650 1651```ts 1652import { appManager } from '@kit.AbilityKit'; 1653import { BusinessError } from '@kit.BasicServicesKit'; 1654 1655let bundleName = "com.example.myapplication"; 1656 1657try { 1658 appManager.isApplicationRunning(bundleName, (err, data) => { 1659 if (err) { 1660 console.error(`err: ${JSON.stringify(err)}`); 1661 } else { 1662 console.log(`The application running is: ${JSON.stringify(data)}`); 1663 } 1664 }); 1665} catch (paramError) { 1666 let code = (paramError as BusinessError).code; 1667 let message = (paramError as BusinessError).message; 1668 console.error(`[appManager] error: ${code}, ${message}`); 1669} 1670``` 1671 1672## ApplicationState 1673 1674Enumerates the application states. This enum can be used together with [AbilityStateData](js-apis-inner-application-appStateData-sys.md) to return the application state. 1675 1676**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1677 1678**System API**: This is a system API. 1679 1680| Name | Value | Description | 1681| -------------------- | --- | --------------------------------- | 1682| STATE_CREATE | 0 | The application is being created. | 1683| STATE_FOREGROUND | 2 | The application is running in the foreground. | 1684| STATE_ACTIVE | 3 | The application is active. | 1685| STATE_BACKGROUND | 4 | The application is running in the background. | 1686| STATE_DESTROY | 5 | The application is being destroyed. | 1687 1688 1689## appManager.getRunningProcessInformationByBundleType<sup>12+</sup> 1690 1691getRunningProcessInformationByBundleType(bundleType: bundleManager.BundleType): Promise\<Array\<ProcessInformation>> 1692 1693Obtains the information about the running process based on the bundle type. This API uses a promise to return the result. 1694 1695**System API**: This is a system API. 1696 1697**Required permissions**: ohos.permission.GET_RUNNING_INFO 1698 1699**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1700 1701**Parameters** 1702 1703| Name | Type | Mandatory | Description | 1704| --------- | ---------------------------------------- | ---- | -------------- | 1705| bundleType | [bundleManager.BundleType](js-apis-bundleManager.md#bundletype) | Yes | Bundle type.| 1706 1707**Return value** 1708 1709| Type| Description| 1710| -------- | -------- | 1711| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the process information.| 1712 1713**Error codes** 1714For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1715 1716| ID| Error Message| 1717| ------- | -------- | 1718| 201 | Permission denied. | 1719| 202 | Not system application. | 1720| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1721| 16000050 | Internal error. | 1722 1723 1724**Example** 1725 1726```ts 1727import { appManager, bundleManager } from '@kit.AbilityKit'; 1728import { BusinessError } from '@kit.BasicServicesKit'; 1729 1730try { 1731 appManager.getRunningProcessInformationByBundleType(bundleManager.BundleType.ATOMIC_SERVICE) 1732 .then((data) => { 1733 console.log(`The running process information is: ${JSON.stringify(data)}`); 1734 }).catch((error: BusinessError) => { 1735 console.error(`error: ${JSON.stringify(error)}`); 1736 }); 1737} catch (paramError) { 1738 let code = (paramError as BusinessError).code; 1739 let message = (paramError as BusinessError).message; 1740 console.error(`[appManager] error: ${code}, ${message}`); 1741} 1742``` 1743 1744## appManager.preloadApplication<sup>12+</sup> 1745 1746preloadApplication(bundleName: string, userId: number, mode: PreloadMode, appIndex?: number): Promise\<void> 1747 1748Preloads an application process. A successful call does not always mean that the preloading is successful. In other words, the target application process may not be created even if the API is successfully called. This API uses a promise to return the result. 1749 1750**Required permissions**: ohos.permission.PRELOAD_APPLICATION 1751 1752**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1753 1754**System API**: This is a system API. 1755 1756**Model restriction**: This API can be used only in the stage model. 1757 1758**Parameters** 1759 1760| Name| Type| Mandatory| Description| 1761| -------- | -------- | -------- | -------- | 1762| bundleName | string | Yes| Bundle name of the application to preload.| 1763| userId | number | Yes| User ID.| 1764| mode | [PreloadMode](#appmanagerpreloadmode12) | Yes| Mode used for preloading.| 1765| appIndex | number | No| Application index of the twin application to be preloaded.| 1766 1767**Return value** 1768 1769| Type | Description | 1770| -------------- | ---------------- | 1771| Promise\<void> | Promise that returns no value.| 1772 1773**Error codes** 1774 1775 For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1776 1777| ID| Error Message| 1778| ------- | -------- | 1779| 201 | The application does not have permission to call the interface. | 1780| 202 | Not system application. | 1781| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1782| 16000050 | Internal error. | 1783| 16300005 | The target bundle does not exist. | 1784 1785**Example** 1786 1787```ts 1788import { appManager } from '@kit.AbilityKit'; 1789import { BusinessError } from '@kit.BasicServicesKit'; 1790import { hilog } from '@kit.PerformanceAnalysisKit'; 1791 1792try { 1793 let bundleName = "ohos.samples.etsclock"; 1794 let userId = 100; 1795 let mode = appManager.PreloadMode.PRESS_DOWN; 1796 let appIndex = 0; 1797 appManager.preloadApplication(bundleName, userId, mode, appIndex) 1798 .then(() => { 1799 hilog.info(0x0000, 'testTag', `preloadApplication success`); 1800 }) 1801 .catch((err: BusinessError) => { 1802 hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${err.code}, msg:${err.message}`); 1803 }) 1804} catch (err) { 1805 hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${(err as BusinessError).code}, msg:${(err as BusinessError).message}`); 1806} 1807``` 1808 1809## appManager.getRunningMultiAppInfo<sup>12+</sup> 1810 1811getRunningMultiAppInfo(bundleName: string): Promise\<RunningMultiAppInfo> 1812 1813Obtains the information about running applications in multi-app mode. This API uses a promise to return the result. The multi-app mode means that an application can be simultaneously logged in with different accounts on the same device. 1814 1815**Required permissions**: ohos.permission.GET_RUNNING_INFO 1816 1817**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1818 1819**System API**: This is a system API. 1820 1821**Model restriction**: This API can be used only in the stage model. 1822 1823**Parameters** 1824 1825| Name| Type| Mandatory| Description| 1826| -------- | -------- | -------- | -------- | 1827| bundleName | string | Yes| Bundle name.| 1828 1829**Return value** 1830 1831| Type | Description | 1832| -------------- | ---------------- | 1833| Promise\<[RunningMultiAppInfo](js-apis-inner-application-runningMultiAppInfo-sys.md)> | Promise used to return the information about running applications with multi-app mode.| 1834 1835**Error codes** 1836 1837 For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1838 1839| ID| Error Message| 1840| ------- | -------- | 1841| 201 | The application does not have permission to call the interface. | 1842| 202 | Not system application. | 1843| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1844| 16000072 | App clone or multi-instance is not supported. | 1845| 18500001 | The bundle does not exist or no patch has been applied. | 1846 1847**Example** 1848 1849```ts 1850import { appManager } from '@kit.AbilityKit'; 1851import { hilog } from '@kit.PerformanceAnalysisKit'; 1852import { BusinessError } from '@kit.BasicServicesKit'; 1853 1854try { 1855 let bundleName = "ohos.samples.etsclock"; 1856 appManager.getRunningMultiAppInfo(bundleName).then((info: appManager.RunningMultiAppInfo) => { 1857 hilog.info(0x0000, 'testTag', `getRunningMultiAppInfo success`); 1858 }).catch((err: BusinessError) => { 1859 hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`); 1860 }) 1861} catch (err) { 1862 hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`); 1863} 1864``` 1865 1866## appManager.isAppRunning<sup>12+</sup> 1867 1868isAppRunning(bundleName: string, appCloneIndex?: number): Promise\<boolean> 1869 1870Checks whether an application is running. This API uses a promise to return the result. 1871 1872**Required permissions**: ohos.permission.GET_RUNNING_INFO 1873 1874**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1875 1876**System API**: This is a system API. 1877 1878**Parameters** 1879 1880| Name| Type| Mandatory| Description| 1881| -------- | -------- | -------- | -------- | 1882| bundleName | string | Yes| Bundle name.| 1883| appCloneIndex | number | No| Index of the app clone.| 1884 1885**Return value** 1886 1887| Type | Description | 1888| -------------- | ---------------- | 1889| Promise\<boolean> | Promise used to return the result. The value **true** means that the application is running, and **false** means the opposite.| 1890 1891**Error codes** 1892 1893 For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1894 1895| ID| Error Message| 1896| ------- | -------- | 1897| 201 | The application does not have permission to call the interface. | 1898| 202 | Not system application. | 1899| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1900| 16000050 | Internal error. | 1901| 16000073 | The app clone index is invalid. | 1902 1903**Example** 1904 1905```ts 1906import { appManager } from '@kit.AbilityKit'; 1907import { hilog } from '@kit.PerformanceAnalysisKit'; 1908import { BusinessError } from '@kit.BasicServicesKit'; 1909 1910try { 1911 let bundleName = "ohos.samples.etsclock"; 1912 appManager.isAppRunning(bundleName).then((data: boolean) => { 1913 hilog.info(0x0000, 'testTag', `data: ${JSON.stringify(data)}`); 1914 }).catch((err: BusinessError) => { 1915 hilog.error(0x0000, 'testTag', `isAppRunning error, code: ${err.code}, msg:${err.message}`); 1916 }) 1917} catch (err) { 1918 hilog.error(0x0000, 'testTag', `isAppRunning error, code: ${err.code}, msg:${err.message}`); 1919} 1920``` 1921 1922## appManager.terminateMission<sup>12+</sup> 1923 1924terminateMission(missionId: number): Promise\<void> 1925 1926Terminates a mission. This API uses a promise to return the result. 1927 1928**Required permissions**: ohos.permission.KILL_APP_PROCESSES 1929 1930**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1931 1932**System API**: This is a system API. 1933 1934**Parameters** 1935 1936| Name| Type| Mandatory| Description| 1937| -------- | -------- | -------- | -------- | 1938| missionId | number | Yes| Mission ID, which can be obtained by calling [getMissionInfos](js-apis-app-ability-missionManager-sys.md#missionmanagergetmissioninfos).| 1939 1940**Return value** 1941 1942| Type| Description| 1943| -------- | -------- | 1944| Promise\<void> | Promise that returns no value.| 1945 1946**Error codes** 1947 1948For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1949 1950| ID| Error Message| 1951| ------- | -------- | 1952| 201 | Permission denied. | 1953| 202 | Not System App. Interface caller is not a system app. | 1954| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1955| 16000050 | Internal error. | 1956 1957**Example** 1958```ts 1959import { appManager } from '@kit.AbilityKit'; 1960import { BusinessError } from '@kit.BasicServicesKit'; 1961 1962@Entry 1963@Component 1964struct Index { 1965 build() { 1966 Button('start link', { type: ButtonType.Capsule, stateEffect: true }) 1967 .width('87%') 1968 .height('5%') 1969 .margin({ bottom: '12vp' }) 1970 .onClick(() => { 1971 let missionId: number = 0; 1972 try { 1973 appManager.terminateMission(missionId).then(()=>{ 1974 console.log('terminateMission success.'); 1975 }).catch((err: BusinessError)=>{ 1976 console.error('terminateMission failed. err: ' + JSON.stringify(err)); 1977 }) 1978 } catch (paramError) { 1979 let code = (paramError as BusinessError).code; 1980 let message = (paramError as BusinessError).message; 1981 console.error(`[appManager] error: ${code}, ${message}`); 1982 } 1983 }) 1984 } 1985} 1986``` 1987 1988## appManager.getSupportedProcessCachePids<sup>13+</sup> 1989 1990getSupportedProcessCachePids(bundleName : string): Promise\<Array\<number>> 1991 1992Obtains the PIDs of processes that support quick startup after caching in a specified application. 1993 1994> **NOTE** 1995> 1996> This API can only be used to obtain the PIDs of the system account to which the caller belongs. 1997 1998**Required permissions**: ohos.permission.GET_RUNNING_INFO 1999 2000**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2001 2002**System API**: This is a system API. 2003 2004**Model restriction**: This API can be used only in the stage model. 2005 2006**Parameters** 2007 2008| Name| Type| Mandatory| Description| 2009| -------- | -------- | -------- | -------- | 2010| bundleName | string | Yes | Bundle name.| 2011 2012**Return value** 2013 2014| Type| Description| 2015| -------- | -------- | 2016| Promise\<Array\<number>> | Promise used to return an array containing the PIDs.| 2017 2018**Error codes** 2019 2020For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2021 2022| ID| Error Message| 2023| ------- | -------- | 2024| 201 | Permission denied. | 2025| 202 | Not system application. | 2026| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2027| 801 | Capability not supported. | 2028| 16000050 | Internal error. | 2029 2030**Example** 2031 2032```ts 2033import { appManager } from '@kit.AbilityKit'; 2034import { hilog } from '@kit.PerformanceAnalysisKit'; 2035import { BusinessError } from '@kit.BasicServicesKit'; 2036 2037try { 2038 let bundleName = "ohos.samples.processcache"; 2039 appManager.getSupportedProcessCachePids(bundleName).then((pids: Array<number>) => { 2040 hilog.info(0x0000, 'testTag', `pids: ${JSON.stringify(pids)}`); 2041 }).catch((err: BusinessError) => { 2042 hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`); 2043 }) 2044} catch (err) { 2045 hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`); 2046} 2047``` 2048