• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ProcessData
2
3The **ProcessData** module defines process data. If a lifecycle change listener is registered by calling [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver), the **onProcessCreated** callback in [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) is invoked when the lifecycle of an application or ability changes.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 8. 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.application.appManager';
13```
14
15## Attributes
16
17**System capability**: SystemCapability.Ability.AbilityRuntime.Core
18
19**System API**: This is a system API and cannot be called by third-party applications.
20
21| Name                    | Type    | Read-only| Mandatory| Description                      |
22| ----------------------- | ---------| ---- | ---- | ------------------------- |
23| pid         | number   | No  | Yes  | Process ID.                   |
24| bundleName  | string   | No  | Yes | Bundle name of the application.                 |
25| uid         | number   | No  | Yes  | UID of the application.                 |
26| isContinuousTask<sup>9+</sup>         | boolean   | No  | Yes  | Whether the task is a continuous task. The value **true** means that the task is a continuous task, and **false** means the opposite.                |
27| isKeepAlive<sup>9+</sup>         | boolean   | No  | Yes  | Whether the process is a resident task. The value **true** means that the process is a resident, and **false** means the opposite.                  |
28| state<sup>9+</sup>       | number   | No  | Yes  | Application state. The options are as follows:<br>**0**: newly created.<br>**1**: ready.<br>**2**: running in the foreground.<br>**4**: running in the background.<br>**5**: terminated.    |
29
30**Example**
31```ts
32import appManager from '@ohos.app.ability.appManager';
33
34let observerCode = appManager.on('applicationState', {
35    onForegroundApplicationChanged(appStateData) {
36        console.log(`onForegroundApplicationChanged appStateData: ${JSON.stringify(appStateData)}`);
37    },
38    onAbilityStateChanged(abilityStateData) {
39        console.log(`onAbilityStateChanged onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
40    },
41    onProcessCreated(processData) {
42        console.log(`onProcessCreated onProcessCreated: ${JSON.stringify(processData)}`);
43    },
44    onProcessDied(processData) {
45        console.log(`onProcessDied onProcessDied: ${JSON.stringify(processData)}`);
46    },
47    onProcessStateChanged(processData) {
48        console.log(`onProcessStateChanged processData.pid : ${JSON.stringify(processData.pid)}`);
49        console.log(`onProcessStateChanged processData.bundleName : ${JSON.stringify(processData.bundleName)}`);
50        console.log(`onProcessStateChanged processData.uid : ${JSON.stringify(processData.uid)}`);
51        console.log(`onProcessStateChanged processData.isContinuousTask : ${JSON.stringify(processData.isContinuousTask)}`);
52        console.log(`onProcessStateChanged processData.isKeepAlive : ${JSON.stringify(processData.isKeepAlive)}`);
53    }
54});
55```
56