js-apis-app-ability-appManager.md 45.2 KB
Newer Older
1
# @ohos.app.ability.appManager (appManager)
2

3
The **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 usage of the application, and information about the running process.
4 5 6 7 8 9 10 11 12 13 14

> **NOTE**
> 
> 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.

## Modules to Import

```ts
import appManager from '@ohos.app.ability.appManager';
```

15
## appManager.isRunningInStabilityTest
16 17 18 19 20 21 22 23 24

static isRunningInStabilityTest(callback: AsyncCallback<boolean>): void

Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

25 26 27
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 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. |
28 29 30 31 32 33 34 35

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
36 37 38

**Example**

39 40
```ts
import appManager from '@ohos.app.ability.appManager';
41

42
appManager.isRunningInStabilityTest((err, flag) => {
G
Gloria 已提交
43
    if (err) {
44
        console.error('isRunningInStabilityTest fail, 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 54 55 56 57 58 59 60 61

static isRunningInStabilityTest(): Promise<boolean>

Checks whether this application is undergoing a stability test. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**

62 63 64
| Type| Description|
| -------- | -------- |
| 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 67 68 69 70 71 72

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
73 74

**Example**
75 76 77 78 79

```ts
import appManager from '@ohos.app.ability.appManager';

appManager.isRunningInStabilityTest().then((flag) => {
80
    console.log('The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}');
81
}).catch((error) => {
82
    console.error('error: ${JSON.stringify(error)}');
83 84
});
```
85 86 87 88 89 90 91 92 93 94 95 96


## appManager.isRamConstrainedDevice

isRamConstrainedDevice(): Promise\<boolean>;

Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**

97 98 99
| Type| Description|
| -------- | -------- |
| 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 102 103 104 105 106 107

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
108 109

**Example**
110 111 112 113 114

```ts
import appManager from '@ohos.app.ability.appManager';

appManager.isRamConstrainedDevice().then((data) => {
115
    console.log('The result of isRamConstrainedDevice is: ${JSON.stringify(data)}');
116
}).catch((error) => {
117
    console.error('error: ${JSON.stringify(error)}');
118 119
});
```
120 121 122 123 124 125 126 127 128 129 130

## appManager.isRamConstrainedDevice

isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;

Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

131 132 133
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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. |
134 135 136 137 138 139 140 141

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
142 143

**Example**
144 145 146 147 148

```ts
import appManager from '@ohos.app.ability.appManager';

appManager.isRamConstrainedDevice((err, data) => {
G
Gloria 已提交
149
    if (err) {
150
        console.error('isRamConstrainedDevice fail, err: ${JSON.stringify(err)}');
151
    } else {
152
        console.log('The result of isRamConstrainedDevice is: ${JSON.stringify(data)}');
153
    }
154
});
155
```
156 157 158 159 160

## appManager.getAppMemorySize

getAppMemorySize(): Promise\<number>;

161
Obtains the memory usage of this application. This API uses a promise to return the result.
162 163 164 165 166

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**

167 168 169
| Type| Description|
| -------- | -------- |
| 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 172 173 174 175 176 177

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
178 179

**Example**
180 181 182 183 184

```ts
import appManager from '@ohos.app.ability.appManager';

appManager.getAppMemorySize().then((data) => {
185
    console.log('The size of app memory is: ${JSON.stringify(data)}');
186
}).catch((error) => {
187
    console.error('error: ${JSON.stringify(error)}');
188 189
});
```
190 191 192 193 194

## appManager.getAppMemorySize

getAppMemorySize(callback: AsyncCallback\<number>): void;

195
Obtains the memory usage of this application. This API uses an asynchronous callback to return the result.
196 197 198 199 200

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

201 202 203
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes|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 206 207 208 209 210 211

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
212 213 214

**Example**

215 216 217 218
```ts
import appManager from '@ohos.app.ability.appManager';

appManager.getAppMemorySize((err, data) => {
G
Gloria 已提交
219
    if (err) {
220
        console.error('getAppMemorySize fail, 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

229
getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>;
230 231 232 233 234 235 236 237 238 239 240

Obtains information about the running processes. This API uses a promise to return the result.

**Required permissions**: ohos.permission.GET_RUNNING_INFO

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**

| Type| Description|
| -------- | -------- |
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 244 245 246 247 248 249

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
250 251

**Example**
252 253 254 255

```ts
import appManager from '@ohos.app.ability.appManager';

256 257
appManager.getRunningProcessInformation().then((data) => {
    console.log('The running process information is: ${JSON.stringify(data)}');
258
}).catch((error) => {
259
    console.error('error: ${JSON.stringify(error)}');
260 261
});
```
262

263
## appManager.getRunningProcessInformation<sup>9+</sup>
264

265
getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>>): void;
266 267 268 269 270 271 272 273 274

Obtains information about the running processes. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.GET_RUNNING_INFO

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

275 276 277
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
278 279 280 281 282 283 284 285

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
286 287

**Example**
288 289 290 291

```ts
import appManager from '@ohos.app.ability.appManager';

292
appManager.getRunningProcessInformation((err, data) => {
G
Gloria 已提交
293
    if (err) {
294
        console.error('getRunningProcessInformation fail, err: ${JSON.stringify(err)}');
295
    } else {
296
        console.log('The process running information is: ${JSON.stringify(data)}');
297
    }
298
});
299
```
300

301
## appManager.isSharedBundleRunning<sup>10+</sup>
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325

isSharedBundleRunning(bundleName: string, versionCode: number): Promise\<boolean>;

Checks whether the shared library is in use. This API uses a promise to return the result.

**Required permissions**: ohos.permission.GET_RUNNING_INFO

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API.

**Parameters**

| Name       | Type                                      | Mandatory  | Description            |
| --------- | ---------------------------------------- | ---- | -------------- |
| bundleName    | string   | Yes   | Bundle name of the shared library.|
| versionCode   | number   | Yes   | Version number of the shared library.     |

**Return value**

| Type| Description|
| -------- | -------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.|

326 327
**Error codes**

328 329
| ID| Error Message|
| ------- | -------- |
330 331 332 333
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).

334 335 336 337 338
**Example**

```ts
import appManager from '@ohos.app.ability.appManager';

339 340
const bundleName = "this is a bundleName";
const versionCode = 1;
341 342 343 344 345 346 347
appManager.isSharedBundleRunning(bundleName, versionCode).then((data) => {
    console.log('The shared bundle running is: ${JSON.stringify(data)}');
}).catch((error) => {
    console.error('error: ${JSON.stringify(error)}');
});
```

348
## appManager.isSharedBundleRunning<sup>10+</sup>
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365

isSharedBundleRunning(bundleName: string, versionCode: number, callback: AsyncCallback\<boolean>): void;

Checks whether the shared library is in use. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.GET_RUNNING_INFO

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API.

**Parameters**

| Name       | Type                                      | Mandatory  | Description            |
| --------- | ---------------------------------------- | ---- | -------------- |
| bundleName    | string   | Yes   | Bundle name of the shared library.|
| versionCode   | number   | Yes   | Version number of the shared library.     |
366
|AsyncCallback\<boolean>> | Callback used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.|
367

368
**Error codes**
369

370 371
| ID| Error Message|
| ------- | -------- |
372 373 374
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
375 376 377 378 379 380

**Example**

```ts
import appManager from '@ohos.app.ability.appManager';

381 382
const bundleName = "this is a bundleName";
const versionCode = 1;
383 384 385 386 387 388 389 390 391
appManager.isSharedBundleRunning(bundleName, versionCode, (err, data) => {
    if (err) {
        console.error('err: ${JSON.stringify(err)}');
    } else {
        console.log('The shared bundle running is: ${JSON.stringify(data)}');
    }
});
```

392 393
## appManager.on

394
on(type: 'applicationState', observer: ApplicationStateObserver): number;
395 396 397 398 399 400 401 402 403 404 405 406 407

Registers an observer to listen for the state changes of all applications.

**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
408
| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.|

**Return value**

| Type| Description|
| --- | --- |
| number | Digital code of the observer, which will be used in **off()** to deregister the observer.|

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
424 425

**Example**
426 427 428 429 430

```ts
import appManager from '@ohos.app.ability.appManager';

let applicationStateObserver = {
431
    onForegroundApplicationChanged(appStateData) {
432
        console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
433 434
    },
    onAbilityStateChanged(abilityStateData) {
435
        console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
436 437
    },
    onProcessCreated(processData) {
438
        console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
439 440
    },
    onProcessDied(processData) {
441
        console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
442 443
    },
    onProcessStateChanged(processData) {
444
        console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
445
    }
446
};
447 448 449 450
try {
    const observerId = appManager.on('applicationState', applicationStateObserver);
    console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
451
    console.error(`[appManager] error: ${paramError.code}, ${paramError.message} `);
452 453
}
```
454 455 456

## appManager.on

457
on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
458 459 460 461 462 463 464 465 466 467 468 469 470

Registers an observer to listen for the state changes of a specified application.

**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
471
| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.|
| bundleNameList | `Array<string>` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.|

**Return value**

| Type| Description|
| --- | --- |
| number | Digital code of the observer, which will be used in **off()** to deregister the observer.|

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
488 489

**Example**
490 491 492 493 494

```ts
import appManager from '@ohos.app.ability.appManager';

let applicationStateObserver = {
495
    onForegroundApplicationChanged(appStateData) {
496
        console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
497 498
    },
    onAbilityStateChanged(abilityStateData) {
499
        console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
500 501
    },
    onProcessCreated(processData) {
502
        console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
503 504
    },
    onProcessDied(processData) {
505
        console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
506 507
    },
    onProcessStateChanged(processData) {
508
        console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
509
    }
510
};
511 512
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
513
    const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
514 515
    console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
516
    console.error(`[appManager] error: ${paramError.code}, ${paramError.message} `);
517 518
}
```
519 520 521

## appManager.off

522
off(type: 'applicationState', observerId: number,  callback: AsyncCallback\<void>): void;
523 524 525 526 527 528 529 530 531 532

Deregisters the application state observer. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**
533

534 535
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
536
| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
537 538 539 540 541 542 543 544 545 546
| observerId | number | Yes| Digital code of the observer.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
547 548 549

**Example**

550 551 552
```ts
import appManager from '@ohos.app.ability.appManager';

G
Gloria 已提交
553
let observerId = 0;
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570

// 1. Register an application state observer.
let applicationStateObserver = {
    onForegroundApplicationChanged(appStateData) {
        console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
    },
    onAbilityStateChanged(abilityStateData) {
        console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
    },
    onProcessCreated(processData) {
        console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
    },
    onProcessDied(processData) {
        console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
    },
    onProcessStateChanged(processData) {
        console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
571
    }
572
};
573 574
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
575
    observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
576 577
    console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
578
    console.error(`[appManager] error: ${paramError.code}, ${paramError.message} `);
579 580 581 582
}

// 2. Deregister the application state observer.
function unregisterApplicationStateObserverCallback(err) {
G
Gloria 已提交
583
    if (err) {
584
        console.error('unregisterApplicationStateObserverCallback fail, err: ${JSON.stringify(err)}');
585
    } else {
586
        console.log('unregisterApplicationStateObserverCallback success.');
587
    }
588 589
}
try {
590
    appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback);
591
} catch (paramError) {
592
    console.error('error: ${paramError.code}, ${paramError.message}');
593 594
}
```
595 596 597

## appManager.off

598
off(type: 'applicationState', observerId: number): Promise\<void>;
599 600 601 602 603 604 605 606 607 608 609 610 611

Deregisters the application state observer. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
612
| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
613
| observerId | number | Yes| Digital code of the observer.|
614 615 616 617 618

**Return value**

| Type| Description|
| -------- | -------- |
619 620 621 622 623 624 625 626 627
| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.|

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
628 629

**Example**
630 631 632 633

```ts
import appManager from '@ohos.app.ability.appManager';

G
Gloria 已提交
634
let observerId = 0;
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651

// 1. Register an application state observer.
let applicationStateObserver = {
    onForegroundApplicationChanged(appStateData) {
        console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
    },
    onAbilityStateChanged(abilityStateData) {
        console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
    },
    onProcessCreated(processData) {
        console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
    },
    onProcessDied(processData) {
        console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
    },
    onProcessStateChanged(processData) {
        console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
652
    }
653
};
654 655
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
656
    observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
657 658
    console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
659
    console.error(`[appManager] error: ${paramError.code}, ${paramError.message} `);
660 661 662 663
}
    
// 2. Deregister the application state observer.
try {
664 665
    appManager.off('applicationState', observerId).then((data) => {
        console.log('unregisterApplicationStateObserver success, data: ${JSON.stringify(data)}');
666
    }).catch((err) => {
667
        console.error('unregisterApplicationStateObserver fail, err: ${JSON.stringify(err)}');
668
    });
669
} catch (paramError) {
670
    console.error('error: ${paramError.code}, ${paramError.message}');
671 672
}
```
673 674 675 676 677

## appManager.getForegroundApplications

getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;

678
Obtains 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).
679 680 681 682 683 684 685

**Required permissions**: ohos.permission.GET_RUNNING_INFO

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

686
**Error codes**
687

688 689 690
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
691

692
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
693 694 695 696 697

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
698
| 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.|
699 700 701

**Example**

702 703
```ts
import appManager from '@ohos.app.ability.appManager';
704

705
function getForegroundApplicationsCallback(err, data) {
G
Gloria 已提交
706
    if (err) {
707
        console.error('getForegroundApplicationsCallback fail, err: ${JSON.stringify(err)}');
708
    } else {
709
        console.log('getForegroundApplicationsCallback success, data: ${JSON.stringify(data)}');
710
    }
711 712 713 714
}
try {
    appManager.getForegroundApplications(getForegroundApplicationsCallback);
} catch (paramError) {
715
    console.error('error: ${paramError.code}, ${paramError.message}');
716 717
}
```
718

719
## appManager.getForegroundApplications
720 721 722

getForegroundApplications(): Promise\<Array\<AppStateData>>;

723
Obtains 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).
724 725 726 727 728 729 730 731 732 733 734

**Required permissions**: ohos.permission.GET_RUNNING_INFO

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Return value**

| Type| Description|
| -------- | -------- |
735
| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Promise used to return an array holding the application state data.|
736 737 738 739 740 741 742 743

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
744 745

**Example**
746 747 748 749 750

```ts
import appManager from '@ohos.app.ability.appManager';

appManager.getForegroundApplications().then((data) => {
751
    console.log('getForegroundApplications success, data: ${JSON.stringify(data)}');
752
}).catch((err) => {
753
    console.error('getForegroundApplications fail, err: ${JSON.stringify(err)}');
754
});
755 756 757
```

## appManager.killProcessWithAccount
758 759 760 761 762

killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>

Kills a process by bundle name and account ID. This API uses a promise to return the result.

G
Gloria 已提交
763 764 765 766
> **NOTE**
>
> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user.

767
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
768 769 770 771 772 773 774

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

775 776 777 778 779 780 781 782 783 784 785 786
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
787 788 789 790

**Example**

```ts
791 792 793 794 795 796
import appManager from '@ohos.app.ability.appManager';

let bundleName = 'bundleName';
let accountId = 0;
try {
    appManager.killProcessWithAccount(bundleName, accountId).then(() => {
797
        console.log('killProcessWithAccount success');
798
    }).catch((err) => {
799
        console.error('killProcessWithAccount fail, err: ${JSON.stringify(err)}');
800
    });
801
} catch (paramError) {
802
    console.error('error: ${paramError.code}, ${paramError.message}');
803
}
804 805 806
```


807
## appManager.killProcessWithAccount
808 809 810 811 812

killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void

Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result.

G
Gloria 已提交
813 814 815 816
> **NOTE**
>
> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user.

817
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
G
Gloria 已提交
818

819 820 821 822 823 824
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

825 826 827 828 829
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
830 831 832 833 834 835 836 837

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
838 839 840 841

**Example**

```ts
842 843 844 845
import appManager from '@ohos.app.ability.appManager';

let bundleName = 'bundleName';
let accountId = 0;
846
function killProcessWithAccountCallback(err, data) {
G
Gloria 已提交
847
    if (err) {
848
        console.error('killProcessWithAccountCallback fail, err: ${JSON.stringify(err)}');
849
    } else {
850
        console.log('killProcessWithAccountCallback success.');
851
    }
852
}
853
appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
854 855
```

856
## appManager.killProcessesByBundleName
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871

killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>);

Kills a process by bundle name. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
872 873 874 875 876 877 878 879 880 881
| bundleName | string | Yes| Bundle name.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
882 883

**Example**
884 885 886 887 888 889

```ts
import appManager from '@ohos.app.ability.appManager';

let bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err, data) {
G
Gloria 已提交
890
    if (err) {
891
        console.error('killProcessesByBundleNameCallback fail, err: ${JSON.stringify(err)}');
892
    } else {
893
        console.log('killProcessesByBundleNameCallback success.');
894
    }
895 896 897 898
}
try {
    appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
} catch (paramError) {
899
    console.error('error: ${paramError.code}, ${paramError.message}');
900 901
}
```
902

903
## appManager.killProcessesByBundleName
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918

killProcessesByBundleName(bundleName: string): Promise\<void>;

Kills a process by bundle name. This API uses a promise to return the result.

**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
919
| bundleName | string | Yes| Bundle name.|
920 921 922 923 924 925 926

**Return value**

| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|

927 928 929 930 931 932 933 934
**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).

935
**Example**
936 937 938 939 940 941 942

```ts
import appManager from '@ohos.app.ability.appManager';

let bundleName = 'bundleName';
try {
    appManager.killProcessesByBundleName(bundleName).then((data) => {
943
        console.log('killProcessesByBundleName success.');
944
    }).catch((err) => {
945
        console.error('killProcessesByBundleName fail, err: ${JSON.stringify(err)}');
946
    });
947
} catch (paramError) {
948
    console.error('error: ${paramError.code}, ${paramError.message}');
949 950 951 952
}
```

## appManager.clearUpApplicationData
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967

clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>);

Clears application data by bundle name. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
968 969 970 971 972 973 974 975 976 977
| bundleName | string | Yes| Bundle name.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
978 979

**Example**
980 981 982 983 984 985

```ts
import appManager from '@ohos.app.ability.appManager';

let bundleName = 'bundleName';
function clearUpApplicationDataCallback(err, data) {
G
Gloria 已提交
986
    if (err) {
987
        console.error('clearUpApplicationDataCallback fail, err: ${JSON.stringify(err)}');
988
    } else {
989
        console.log('clearUpApplicationDataCallback success.');
990
    }
991 992 993 994
}
try {
    appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
} catch (paramError) {
995
    console.error('error: ${paramError.code}, ${paramError.message}');
996 997
}
```
998

999
## appManager.clearUpApplicationData
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014

clearUpApplicationData(bundleName: string): Promise\<void>;

Clears application data by bundle name. This API uses a promise to return the result.

**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
1015
| bundleName | string | Yes| Bundle name.|
1016 1017 1018 1019 1020

**Return value**

| Type| Description|
| -------- | -------- |
1021 1022 1023 1024 1025 1026 1027 1028 1029
| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.|

**Error codes**

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
1030 1031

**Example**
1032 1033 1034 1035 1036 1037 1038

```ts
import appManager from '@ohos.app.ability.appManager';

let bundleName = 'bundleName';
try {
    appManager.clearUpApplicationData(bundleName).then((data) => {
1039
        console.log('clearUpApplicationData success.');
1040
    }).catch((err) => {
1041
        console.error('clearUpApplicationData fail, err: ${JSON.stringify(err)}');
1042
    });
1043
} catch (paramError) {
1044
    console.error('error: ${paramError.code}, ${paramError.message}');
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
}
```

## appManager.getProcessMemoryByPid<sup>10+</sup>

getProcessMemoryByPid(pid: number, callback: AsyncCallback\<number>): void;

Obtains the memory usage of a process. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinfobybundlename10).|
| 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.|

**Error codes**

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

**Example**

```ts
import appManager from '@ohos.app.ability.appManager';

let pid = 0;
function getProcessMemoryByPidCallback(err, data) {
    if (err) {
        console.error('getProcessMemoryByPidCallback fail, err: ${JSON.stringify(err)}');
    } else {
        console.log('getProcessMemoryByPidCallback success.');
    }
}
try {
    appManager.getProcessMemoryByPid(pid, getProcessMemoryByPidCallback);
} catch (paramError) {
    console.error('error: ${paramError.code}, ${paramError.message}');
}
```

## appManager.getProcessMemoryByPid<sup>10+</sup>

getProcessMemoryByPid(pid: number): Promise\<number>;

Obtains the memory usage of a process. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinfobybundlename10). |

**Return value**

| Type| Description|
| -------- | -------- |
| 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.|

**Error codes**

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

**Example**

```ts
import appManager from '@ohos.app.ability.appManager';

let pid = 0;
try {
    appManager.getProcessMemoryByPid(pid).then((data) => {
        console.log('getProcessMemoryByPid success.');
    }).catch((err) => {
        console.error('getProcessMemoryByPid fail, err: ${JSON.stringify(err)}');
    });
} catch (paramError) {
    console.error('error: ${paramError.code}, ${paramError.message}');
}
```

## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>

getRunningProcessInfoByBundleName(bundleName: string, callback: AsyncCallback\<Array\<ProcessInformation>>): void;

Obtains information about the running processes by bundle name. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| 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.|

**Error codes**

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

**Example**

```ts
import appManager from '@ohos.app.ability.appManager';

let bundleName = "bundleName";
function getRunningProcessInfoByBundleNameCallback(err, data) {
    if (err) {
        console.error('getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}');
    } else {
        console.log('getRunningProcessInfoByBundleNameCallback success.');
    }
}
try {
    appManager.getRunningProcessInfoByBundleName(bundleName, getRunningProcessInfoByBundleNameCallback);
} catch (paramError) {
    console.error('error: ${paramError.code}, ${paramError.message}');
}
```

## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>

getRunningProcessInfoByBundleName(bundleName: string): Promise\<Array\<ProcessInformation>>;

Obtains information about the running processes by bundle name. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|

**Return value**

| Type| Description|
| -------- | -------- |
| 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.|

**Error codes**

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

**Example**

```ts
import appManager from '@ohos.app.ability.appManager';

let bundleName = "bundleName";
try {
    appManager.getRunningProcessInfoByBundleName(bundleName).then((data) => {
        console.log('getRunningProcessInfoByBundleName success.');
    }).catch((err) => {
        console.error('getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}');
    });
} catch (paramError) {
    console.error('error: ${paramError.code}, ${paramError.message}');
}
```

## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>

getRunningProcessInfoByBundleName(bundleName: string, userId: number, callback: AsyncCallback\<Array\<ProcessInformation>>): void;

Obtains information about the running processes by bundle name and user ID. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| userId | number | Yes| User ID.|
| 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.|

**Error codes**

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

**Example**

```ts
import appManager from '@ohos.app.ability.appManager';

let bundleName = "bundleName";
let userId = 0;
function getRunningProcessInfoByBundleNameCallback(err, data) {
    if (err) {
        console.error('getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}');
    } else {
        console.log('getRunningProcessInfoByBundleNameCallback success.');
    }
}
try {
    appManager.getRunningProcessInfoByBundleName(bundleName, userId, getRunningProcessInfoByBundleNameCallback);
} catch (paramError) {
    console.error('error: ${paramError.code}, ${paramError.message}');
}
```

## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>

getRunningProcessInfoByBundleName(bundleName: string, userId: number): Promise\<Array\<ProcessInformation>>;

Obtains information about the running processes by bundle name and user ID. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| userId | number | Yes| User ID.|

**Return value**

| Type| Description|
| -------- | -------- |
| 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.|

**Error codes**

For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).

| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |

**Example**

```ts
import appManager from '@ohos.app.ability.appManager';

let bundleName = "bundleName";
let userId = 0;
try {
    appManager.getRunningProcessInfoByBundleName(bundleName, userId).then((data) => {
        console.log('getRunningProcessInfoByBundleName success.');
    }).catch((err) => {
        console.error('getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}');
    });
} catch (paramError) {
    console.error('error: ${paramError.code}, ${paramError.message}');
1325 1326
}
```
1327

1328 1329 1330
## ApplicationState

Enumerates the application states. This enum can be used together with [AbilityStateData](js-apis-inner-application-appStateData.md) to return the application state.
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

| Name                | Value | Description                              |
| -------------------- | --- | --------------------------------- |
| STATE_CREATE    | 1   |   State indicating that the application is being created.        |
| STATE_FOREGROUND          | 2   |      State indicating that the application is running in the foreground.           |
| STATE_ACTIVE  | 3   |         State indicating that the application is active.    |
| STATE_BACKGROUND        | 4   |       State indicating that the application is running in the background.          |
| STATE_DESTROY        | 5   |           State indicating that the application is destroyed.      |

1344 1345 1346
## ProcessState

Enumerates the process states. This enum can be used together with [ProcessData](js-apis-inner-application-processData.md) to return the process state.
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**System API**: This is a system API and cannot be called by third-party applications.

| Name                | Value | Description                              |
| -------------------- | --- | --------------------------------- |
| STATE_CREATE    | 1   |      State indicating that the process is being created.      |
| STATE_FOREGROUND          | 2   |            State indicating that the process is running in the foreground.     |
| STATE_ACTIVE  | 3   |          State indicating that the process is active.  |
| STATE_BACKGROUND        | 4   |       State indicating that the process is running in the background.          |
| STATE_DESTROY        | 5   |         State indicating that the process is destroyed.        |