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