• 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#appmanagerregisterapplicationstateobserver8), 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**System capability**: SystemCapability.Ability.AbilityRuntime.Core
16
17**System API**: This is a system API and cannot be called by third-party applications.
18
19| Name                    | Type    | Readable| Writable| Description                      |
20| ----------------------- | ---------| ---- | ---- | ------------------------- |
21| pid         | number   | Yes  | No  | Process ID.                   |
22| bundleName  | string   | Yes  | No | Bundle name of the application.                 |
23| uid         | number   | Yes  | No  | UID of the application.                 |
24| isContinuousTask<sup>9+</sup>         | boolean   | Yes  | No  | Whether the task is a continuous task. The value **true** means that the task is a continuous task, and **false** means the opposite.                |
25| isKeepAlive<sup>9+</sup>         | boolean   | Yes  | No  | Whether the process is a resident task. The value **true** means that the process is a resident, and **false** means the opposite.                  |
26| state<sup>9+</sup>       | number   | Yes  | No  | Application state. The value can be **0** (newly created), **2** (foreground), **4** (background), or **5** (terminated).    |
27
28**Example**
29```ts
30import appManager from '@ohos.application.appManager';
31
32let applicationStateObserver = {
33    onForegroundApplicationChanged(appStateData) {
34        console.log('onForegroundApplicationChanged appStateData: ' +  JSON.stringify(appStateData));
35    },
36    onAbilityStateChanged(abilityStateData) {
37        console.log('onAbilityStateChanged onAbilityStateChanged: ' +  JSON.stringify(abilityStateData));
38    },
39    onProcessCreated(processData) {
40        console.log('onProcessCreated onProcessCreated: '  +  JSON.stringify(processData));
41    },
42    onProcessDied(processData) {
43        console.log('onProcessDied onProcessDied: '  +  JSON.stringify(processData));
44    },
45    onProcessStateChanged(processData) {
46        console.log('onProcessStateChanged processData.pid : ' +  JSON.stringify(processData.pid));
47        console.log('onProcessStateChanged processData.bundleName : ' +  JSON.stringify(processData.bundleName));
48        console.log('onProcessStateChanged processData.uid : ' +  JSON.stringify(processData.uid));
49        console.log('onProcessStateChanged processData.isContinuousTask : ' +  JSON.stringify(processData.isContinuousTask));
50        console.log('onProcessStateChanged processData.isKeepAlive : ' +  JSON.stringify(processData.isKeepAlive));
51    }
52};
53let observerCode = appManager.registerApplicationStateObserver(applicationStateObserver);
54```
55