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