• 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 '@kit.AbilityKit';
13```
14
15## ProcessState<sup>10+</sup>
16
17Enumerates the processes states.
18
19**Atomic service API**: This API can be used in atomic services since API version 11.
20
21**System capability**: SystemCapability.Ability.AbilityRuntime.Core
22
23| Name                | Value | Description                              |
24| -------------------- | --- | --------------------------------- |
25| STATE_CREATE    | 0   |    The process is being created.      |
26| STATE_FOREGROUND          | 1   |    The process is running in the foreground.     |
27| STATE_ACTIVE  | 2   |     The process is active.  |
28| STATE_BACKGROUND        | 3   |    The process is running in the background.          |
29| STATE_DESTROY        | 4   |    The process is being destroyed.        |
30
31## appManager.isRunningInStabilityTest
32
33isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void
34
35Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result.
36
37**Atomic service API**: This API can be used in atomic services since API version 11.
38
39**System capability**: SystemCapability.Ability.AbilityRuntime.Core
40
41**Parameters**
42
43  | Name| Type| Mandatory| Description|
44  | -------- | -------- | -------- | -------- |
45  | callback | AsyncCallback&lt;boolean&gt; | Yes|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. |
46
47**Error codes**
48
49For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
50
51| ID| Error Message|
52| ------- | -------- |
53| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
54| 16000050 | Internal error. |
55
56**Example**
57
58```ts
59import { appManager } from '@kit.AbilityKit';
60
61appManager.isRunningInStabilityTest((err, flag) => {
62  if (err) {
63    console.error(`isRunningInStabilityTest fail, err: ${JSON.stringify(err)}`);
64  } else {
65    console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`);
66  }
67});
68```
69
70
71## appManager.isRunningInStabilityTest
72
73isRunningInStabilityTest(): Promise&lt;boolean&gt;
74
75Checks whether this application is undergoing a stability test. This API uses a promise to return the result.
76
77**Atomic service API**: This API can be used in atomic services since API version 11.
78
79**System capability**: SystemCapability.Ability.AbilityRuntime.Core
80
81**Return value**
82
83  | Type| Description|
84  | -------- | -------- |
85  | 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 undergoing a stability test, and **false** means the opposite.|
86
87**Error codes**
88
89For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
90
91| ID| Error Message|
92| ------- | -------- |
93| 16000050 | Internal error. |
94
95**Example**
96
97```ts
98import { appManager } from '@kit.AbilityKit';
99import { BusinessError } from '@kit.BasicServicesKit';
100
101appManager.isRunningInStabilityTest().then((flag) => {
102  console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`);
103}).catch((error: BusinessError) => {
104  console.error(`error: ${JSON.stringify(error)}`);
105});
106```
107
108
109## appManager.isRamConstrainedDevice
110
111isRamConstrainedDevice(): Promise\<boolean>
112
113Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result.
114
115**Atomic service API**: This API can be used in atomic services since API version 11.
116
117**System capability**: SystemCapability.Ability.AbilityRuntime.Core
118
119**Return value**
120
121  | Type| Description|
122  | -------- | -------- |
123  | 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.|
124
125**Error codes**
126
127For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
128
129| ID| Error Message|
130| ------- | -------- |
131| 16000050 | Internal error. |
132
133**Example**
134
135```ts
136import { appManager } from '@kit.AbilityKit';
137import { BusinessError } from '@kit.BasicServicesKit';
138
139appManager.isRamConstrainedDevice().then((data) => {
140  console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`);
141}).catch((error: BusinessError) => {
142  console.error(`error: ${JSON.stringify(error)}`);
143});
144```
145
146## appManager.isRamConstrainedDevice
147
148isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void
149
150Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result.
151
152**Atomic service API**: This API can be used in atomic services since API version 11.
153
154**System capability**: SystemCapability.Ability.AbilityRuntime.Core
155
156**Parameters**
157
158  | Name| Type| Mandatory| Description|
159  | -------- | -------- | -------- | -------- |
160  | callback | AsyncCallback&lt;boolean&gt; | Yes|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. |
161
162**Error codes**
163
164For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
165
166| ID| Error Message|
167| ------- | -------- |
168| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
169| 16000050 | Internal error. |
170
171**Example**
172
173```ts
174import { appManager } from '@kit.AbilityKit';
175
176appManager.isRamConstrainedDevice((err, data) => {
177  if (err) {
178    console.error(`isRamConstrainedDevice fail, err: ${JSON.stringify(err)}`);
179  } else {
180    console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`);
181  }
182});
183```
184
185## appManager.getAppMemorySize
186
187getAppMemorySize(): Promise\<number>
188
189Obtains the memory size of this application. This API uses a promise to return the result.
190
191**Atomic service API**: This API can be used in atomic services since API version 11.
192
193**System capability**: SystemCapability.Ability.AbilityRuntime.Core
194
195**Return value**
196
197  | Type| Description|
198  | -------- | -------- |
199  | Promise&lt;number&gt; | Promise used to return the memory size, in MB. You can perform error processing or other custom processing based on the size.  |
200
201**Error codes**
202
203For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
204
205| ID| Error Message|
206| ------- | -------- |
207| 16000050 | Internal error. |
208
209**Example**
210
211```ts
212import { appManager } from '@kit.AbilityKit';
213import { BusinessError } from '@kit.BasicServicesKit';
214
215appManager.getAppMemorySize().then((data) => {
216  console.log(`The size of app memory is: ${JSON.stringify(data)}`);
217}).catch((error: BusinessError) => {
218  console.error(`error: ${JSON.stringify(error)}`);
219});
220```
221
222## appManager.getAppMemorySize
223
224getAppMemorySize(callback: AsyncCallback\<number>): void
225
226Obtains the memory size of this application. This API uses an asynchronous callback to return the result.
227
228**Atomic service API**: This API can be used in atomic services since API version 11.
229
230**System capability**: SystemCapability.Ability.AbilityRuntime.Core
231
232**Parameters**
233
234  | Name| Type| Mandatory| Description|
235  | -------- | -------- | -------- | -------- |
236  | callback | AsyncCallback&lt;number&gt; | Yes|Callback used to return the memory size, in MB. You can perform error processing or other custom processing based on the size.  |
237
238**Error codes**
239
240For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
241
242| ID| Error Message|
243| ------- | -------- |
244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
245| 16000050 | Internal error. |
246
247**Example**
248
249```ts
250import { appManager } from '@kit.AbilityKit';
251
252appManager.getAppMemorySize((err, data) => {
253  if (err) {
254    console.error(`getAppMemorySize fail, err: ${JSON.stringify(err)}`);
255  } else {
256    console.log(`The size of app memory is: ${JSON.stringify(data)}`);
257  }
258});
259```
260
261## appManager.getRunningProcessInformation
262
263getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>
264
265Obtains information about the running processes of this application. This API uses a promise to return the result.
266
267> **NOTE**
268>
269> - In versions earlier than API version 11, this API requires the **ohos.permission.GET_RUNNING_INFO** permission, which is available only for system applications.
270> - Since API version 11, this API is used only to obtain the process information of the caller. No permission is required.
271
272**Atomic service API**: This API can be used in atomic services since API version 11.
273
274**System capability**: SystemCapability.Ability.AbilityRuntime.Core
275
276**Return value**
277
278| Type| Description|
279| -------- | -------- |
280| 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.|
281
282**Error codes**
283
284For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
285
286| ID| Error Message|
287| ------- | -------- |
288| 16000050 | Internal error. |
289
290**Example**
291
292```ts
293import { appManager } from '@kit.AbilityKit';
294import { BusinessError } from '@kit.BasicServicesKit';
295
296appManager.getRunningProcessInformation().then((data) => {
297  console.log(`The running process information is: ${JSON.stringify(data)}`);
298}).catch((error: BusinessError) => {
299  console.error(`error: ${JSON.stringify(error)}`);
300});
301```
302
303## appManager.getRunningProcessInformation
304
305getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>>): void
306
307Obtains information about the running processes of this application. This API uses an asynchronous callback to return the result.
308
309> **NOTE**
310>
311> - In versions earlier than API version 11, this API requires the **ohos.permission.GET_RUNNING_INFO** permission, which is available only for system applications.
312> - Since API version 11, this API is used only to obtain the process information of the caller. No permission is required.
313
314**Atomic service API**: This API can be used in atomic services since API version 11.
315
316**System capability**: SystemCapability.Ability.AbilityRuntime.Core
317
318**Parameters**
319
320  | Name| Type| Mandatory| Description|
321  | -------- | -------- | -------- | -------- |
322  | 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.|
323
324**Error codes**
325
326For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
327
328| ID| Error Message|
329| ------- | -------- |
330| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
331| 16000050 | Internal error. |
332
333**Example**
334
335```ts
336import { appManager } from '@kit.AbilityKit';
337
338appManager.getRunningProcessInformation((err, data) => {
339  if (err) {
340    console.error(`getRunningProcessInformation fail, err: ${JSON.stringify(err)}`);
341  } else {
342    console.log(`The running process information is: ${JSON.stringify(data)}`);
343  }
344});
345```
346
347## appManager.on('applicationState')<sup>14+</sup>
348
349on(type: 'applicationState', observer: ApplicationStateObserver): number
350
351Registers an observer to listen for the state changes of all applications.
352
353**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
354
355**System capability**: SystemCapability.Ability.AbilityRuntime.Core
356
357**Parameters**
358
359| Name| Type| Mandatory| Description|
360| -------- | -------- | -------- | -------- |
361| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
362| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.|
363
364**Return value**
365
366| Type| Description|
367| --- | --- |
368| number | Digital code of the observer, which will be used in **off()** to deregister the observer.|
369
370**Error codes**
371
372For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
373
374| ID| Error Message|
375| ------- | -------- |
376| 201 | Permission denied. |
377| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
378| 16000050 | Internal error. |
379
380**Example**
381
382```ts
383import { appManager } from '@kit.AbilityKit';
384import { BusinessError } from '@kit.BasicServicesKit';
385
386let applicationStateObserver: appManager.ApplicationStateObserver = {
387  onForegroundApplicationChanged(appStateData) {
388    console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
389  },
390  onAbilityStateChanged(abilityStateData) {
391    console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
392  },
393  onProcessCreated(processData) {
394    console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
395  },
396  onProcessDied(processData) {
397    console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
398  },
399  onProcessStateChanged(processData) {
400    console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
401  },
402  onAppStarted(appStateData) {
403    console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`);
404  },
405  onAppStopped(appStateData) {
406    console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`);
407  }
408};
409
410try {
411  const observerId = appManager.on('applicationState', applicationStateObserver);
412  console.log(`[appManager] observerCode: ${observerId}`);
413} catch (paramError) {
414  let code = (paramError as BusinessError).code;
415  let message = (paramError as BusinessError).message;
416  console.error(`[appManager] error: ${code}, ${message}`);
417}
418```
419
420## appManager.on('applicationState')<sup>14+</sup>
421
422on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number
423
424Registers an observer to listen for the state changes of a specified application.
425
426**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
427
428**System capability**: SystemCapability.Ability.AbilityRuntime.Core
429
430**Parameters**
431
432| Name| Type| Mandatory| Description|
433| -------- | -------- | -------- | -------- |
434| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
435| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.|
436| bundleNameList | `Array<string>` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.|
437
438**Return value**
439
440| Type| Description|
441| --- | --- |
442| number | Digital code of the observer, which will be used in **off()** to deregister the observer.|
443
444**Error codes**
445
446For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
447
448| ID| Error Message|
449| ------- | -------- |
450| 201 | Permission denied. |
451| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
452| 16000050 | Internal error. |
453
454**Example**
455
456```ts
457import { appManager } from '@kit.AbilityKit';
458import { BusinessError } from '@kit.BasicServicesKit';
459
460let applicationStateObserver: appManager.ApplicationStateObserver = {
461  onForegroundApplicationChanged(appStateData) {
462    console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
463  },
464  onAbilityStateChanged(abilityStateData) {
465    console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
466  },
467  onProcessCreated(processData) {
468    console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
469  },
470  onProcessDied(processData) {
471    console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
472  },
473  onProcessStateChanged(processData) {
474    console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
475  },
476  onAppStarted(appStateData) {
477    console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`);
478  },
479  onAppStopped(appStateData) {
480    console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`);
481  }
482};
483
484let bundleNameList = ['bundleName1', 'bundleName2'];
485
486try {
487  const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
488  console.log(`[appManager] observerCode: ${observerId}`);
489} catch (paramError) {
490  let code = (paramError as BusinessError).code;
491  let message = (paramError as BusinessError).message;
492  console.error(`[appManager] error: ${code}, ${message}`);
493}
494```
495
496## appManager.off('applicationState')<sup>14+</sup>
497
498off(type: 'applicationState', observerId: number): Promise\<void>
499
500Deregisters the application state observer. This API uses a promise to return the result.
501
502**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
503
504**System capability**: SystemCapability.Ability.AbilityRuntime.Core
505
506**Parameters**
507
508| Name| Type| Mandatory| Description|
509| -------- | -------- | -------- | -------- |
510| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
511| observerId | number | Yes| Digital code of the observer.|
512
513**Return value**
514
515| Type| Description|
516| -------- | -------- |
517| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.|
518
519**Error codes**
520
521For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
522
523| ID| Error Message|
524| ------- | -------- |
525| 201 | Permission denied. |
526| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
527| 16000050 | Internal error. |
528
529**Example**
530
531```ts
532import { appManager } from '@kit.AbilityKit';
533import { BusinessError } from '@kit.BasicServicesKit';
534
535let observerId = 0;
536
537// 1. Register an application state observer.
538let applicationStateObserver: appManager.ApplicationStateObserver = {
539  onForegroundApplicationChanged(appStateData) {
540    console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
541  },
542  onAbilityStateChanged(abilityStateData) {
543    console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
544  },
545  onProcessCreated(processData) {
546    console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
547  },
548  onProcessDied(processData) {
549    console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
550  },
551  onProcessStateChanged(processData) {
552    console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
553  },
554  onAppStarted(appStateData) {
555    console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`);
556  },
557  onAppStopped(appStateData) {
558    console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`);
559  }
560};
561let bundleNameList = ['bundleName1', 'bundleName2'];
562
563try {
564  observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
565} catch (paramError) {
566  let code = (paramError as BusinessError).code;
567  let message = (paramError as BusinessError).message;
568  console.error(`[appManager] error: ${code}, ${message}`);
569}
570
571// 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: BusinessError) => {
576    console.error(`unregisterApplicationStateObserver fail, err: ${JSON.stringify(err)}`);
577  });
578} catch (paramError) {
579  let code = (paramError as BusinessError).code;
580  let message = (paramError as BusinessError).message;
581  console.error(`[appManager] error: ${code}, ${message}`);
582}
583```
584
585## appManager.off('applicationState')<sup>15+</sup>
586
587off(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>): void
588
589Deregisters the application state observer. This API uses an asynchronous callback to return the result.
590
591**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
592
593**System capability**: SystemCapability.Ability.AbilityRuntime.Core
594
595**Parameters**
596
597| Name| Type| Mandatory| Description|
598| -------- | -------- | -------- | -------- |
599| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
600| observerId | number | Yes| Digital code of the observer.|
601| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the application state observer is deregistered, **err** is undefined; otherwise, **error** is an error object.|
602
603**Error codes**
604
605For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
606
607| ID| Error Message|
608| ------- | -------- |
609| 201 | Permission denied. |
610| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
611| 16000050 | Internal error. |
612
613**Example**
614
615```ts
616import { appManager } from '@kit.AbilityKit';
617import { BusinessError } from '@kit.BasicServicesKit';
618
619let observerId = 0;
620
621// 1. Register an application state observer.
622let applicationStateObserver: appManager.ApplicationStateObserver = {
623  onForegroundApplicationChanged(appStateData) {
624    console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
625  },
626  onAbilityStateChanged(abilityStateData) {
627    console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
628  },
629  onProcessCreated(processData) {
630    console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
631  },
632  onProcessDied(processData) {
633    console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
634  },
635  onProcessStateChanged(processData) {
636    console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
637  },
638  onAppStarted(appStateData) {
639    console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`);
640  },
641  onAppStopped(appStateData) {
642    console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`);
643  }
644};
645let bundleNameList = ['bundleName1', 'bundleName2'];
646
647try {
648  observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
649} catch (paramError) {
650  let code = (paramError as BusinessError).code;
651  let message = (paramError as BusinessError).message;
652  console.error(`[appManager] error: ${code}, ${message}`);
653}
654
655// 2. Deregister the application state observer.
656try {
657  function offCallback((err: BusinessError)  => {
658    if (err) {
659      console.error(`appmanager.off failed, code: ${err.code}, msg: ${err.message}`);
660    } else {
661      console.info(`appmanager.off success.`);
662    }
663  })
664  appManager.off('applicationState', observerId, offCallback);
665} catch (paramError) {
666  let code = (paramError as BusinessError).code;
667  let message = (paramError as BusinessError).message;
668  console.error(`[appManager] error: ${code}, ${message}`);
669}
670```
671
672## appManager.killProcessesByBundleName<sup>14+</sup>
673
674killProcessesByBundleName(bundleName: string, clearPageStack: boolean, appIndex?: number): Promise\<void>
675
676Kills a process by bundle name. This API uses an asynchronous callback to return the result. This API uses a promise to return the result.
677
678**Required permissions**: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES
679
680**System capability**: SystemCapability.Ability.AbilityRuntime.Core
681
682**Parameters**
683
684| Name| Type| Mandatory| Description|
685| -------- | -------- | -------- | -------- |
686| bundleName | string | Yes| Bundle name.|
687| clearPageStack | boolean | Yes| Whether to clear the page stack. The value **true** means to clear the page stack, and **false** means the opposite.|
688| appIndex | number | No| Index of an application clone.|
689
690**Return value**
691
692| Type| Description|
693| -------- | -------- |
694| Promise\<void> | Promise that returns no value.|
695
696**Error codes**
697
698For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
699
700| ID| Error Message|
701| ------- | -------- |
702| 201 | Permission denied. |
703| 401 | If the input parameter is not valid parameter. |
704| 16000050 | Internal error. |
705
706**Example**
707
708```ts
709import { appManager } from '@kit.AbilityKit';
710import { BusinessError } from '@kit.BasicServicesKit';
711
712let bundleName = 'bundleName';
713let isClearPageStack = false;
714let appIndex = 1;
715
716try {
717  appManager.killProcessesByBundleName(bundleName, isClearPageStack, appIndex).then((data) => {
718    console.log('killProcessesByBundleName success.');
719  }).catch((err: BusinessError) => {
720    console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`);
721  });
722} catch (paramError) {
723  let code = (paramError as BusinessError).code;
724  let message = (paramError as BusinessError).message;
725  console.error(`[appManager] error: ${code}, ${message}`);
726}
727```
728
729## appManager.isAppRunning<sup>14+</sup>
730
731isAppRunning(bundleName: string, appCloneIndex?: number): Promise\<boolean>
732
733Checks whether an application is running. This API uses a promise to return the result.
734
735**Required permissions**: ohos.permission.GET_RUNNING_INFO
736
737**System capability**: SystemCapability.Ability.AbilityRuntime.Core
738
739**Parameters**
740
741| Name| Type| Mandatory| Description|
742| -------- | -------- | -------- | -------- |
743| bundleName | string | Yes| Bundle name.|
744| appCloneIndex | number | No| Index of an application clone.|
745
746**Return value**
747
748| Type          | Description             |
749| -------------- | ---------------- |
750| Promise\<boolean> | Promise used to return the result. The value **true** means that the application is running, and **false** means the opposite.|
751
752**Error codes**
753
754  For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
755
756| ID| Error Message|
757| ------- | -------- |
758| 201 | Permission denied. |
759| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
760| 16000050 | Internal error. |
761| 16000073 | The app clone index is invalid. |
762
763**Example**
764
765```ts
766import { appManager } from '@kit.AbilityKit';
767import { hilog } from '@kit.PerformanceAnalysisKit';
768import { BusinessError } from '@kit.BasicServicesKit';
769
770try {
771  let bundleName = "ohos.samples.etsclock";
772  appManager.isAppRunning(bundleName).then((data: boolean) => {
773      hilog.info(0x0000, 'testTag', `data: ${JSON.stringify(data)}`);
774    }).catch((err: BusinessError) => {
775      hilog.error(0x0000, 'testTag', `isAppRunning error, code: ${err.code}, msg:${err.message}`);
776    })
777} catch (err) {
778  hilog.error(0x0000, 'testTag', `isAppRunning error, code: ${err.code}, msg:${err.message}`);
779}
780```
781
782## ApplicationStateObserver<sup>14+</sup>
783
784type ApplicationStateObserver = _ApplicationStateObserver.default
785
786Defines the ApplicationStateObserver module.
787
788**System capability**: SystemCapability.Ability.AbilityRuntime.Core
789
790| Type| Description|
791| --- | --- |
792| [_ApplicationStateObserver.default](js-apis-inner-application-applicationStateObserver.md) | ApplicationStateObserver module.|
793
794## ProcessInformation
795
796type ProcessInformation = _ProcessInformation
797
798Defines the ProcessInformation module.
799
800**Atomic service API**: This API can be used in atomic services since API version 11.
801
802**System capability**: SystemCapability.Ability.AbilityRuntime.Core
803
804| Type| Description|
805| --- | --- |
806| [_ProcessInformation](js-apis-inner-application-processInformation.md) | ProcessInformation module.|
807