• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ProcessData (System API)
2
3The **ProcessData** module defines process data. If a lifecycle change listener is registered by calling [registerApplicationStateObserver](js-apis-application-appManager-sys.md#appmanagerregisterapplicationstateobserver), the **onProcessCreated** callback in [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver-sys.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> The APIs provided by this module are system APIs.
9
10## Modules to Import
11
12```ts
13import { appManager } from '@kit.AbilityKit';
14```
15
16## Properties
17
18**System capability**: SystemCapability.Ability.AbilityRuntime.Core
19
20**System API**: This is a system API and cannot be called by third-party applications.
21
22| Name                    | Type    | Read-only | Mandatory | Description                      |
23| ----------------------- | ---------| ---- | ---- | ------------------------- |
24| pid         | number   | No  | Yes  | Process ID.                   |
25| bundleName  | string   | No  | Yes | Bundle name of the application.                 |
26| uid         | number   | No  | Yes  | UID of the application.                 |
27| 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.                |
28| 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.                  |
29| 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.    |
30
31**Example**
32```ts
33import { appManager } from '@kit.AbilityKit';
34
35let observerCode = appManager.on('applicationState', {
36  onForegroundApplicationChanged(appStateData) {
37    console.log(`onForegroundApplicationChanged appStateData: ${JSON.stringify(appStateData)}`);
38  },
39  onAbilityStateChanged(abilityStateData) {
40    console.log(`onAbilityStateChanged onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
41  },
42  onProcessCreated(processData) {
43    console.log(`onProcessCreated onProcessCreated: ${JSON.stringify(processData)}`);
44  },
45  onProcessDied(processData) {
46    console.log(`onProcessDied onProcessDied: ${JSON.stringify(processData)}`);
47  },
48  onProcessStateChanged(processData) {
49    console.log(`onProcessStateChanged processData.pid : ${JSON.stringify(processData.pid)}`);
50    console.log(`onProcessStateChanged processData.bundleName : ${JSON.stringify(processData.bundleName)}`);
51    console.log(`onProcessStateChanged processData.uid : ${JSON.stringify(processData.uid)}`);
52    console.log(`onProcessStateChanged processData.isContinuousTask : ${JSON.stringify(processData.isContinuousTask)}`);
53    console.log(`onProcessStateChanged processData.isKeepAlive : ${JSON.stringify(processData.isKeepAlive)}`);
54  },
55  onAppStarted(appStateData) {
56    console.log(`onAppStarted appStateData: ${JSON.stringify(appStateData)}`);
57  },
58  onAppStopped(appStateData) {
59    console.log(`onAppStopped appStateData: ${JSON.stringify(appStateData)}`);
60  }
61});
62```
63