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