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