• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ProcessData
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @SKY2001-->
5<!--Designer: @yzkp-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9The module defines process data. If a lifecycle change listener is registered by calling [on](js-apis-app-ability-appManager.md#appmanageronapplicationstate14), the **onProcessCreated** callback in [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) is invoked when the lifecycle of an application or ability changes.
10
11> **NOTE**
12>
13> The initial APIs of this module are supported since API version 14. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14
15## Modules to Import
16
17```ts
18import { appManager } from '@kit.AbilityKit';
19```
20
21## Properties
22
23**System capability**: SystemCapability.Ability.AbilityRuntime.Core
24
25| Name        | Type    | Read-Only| Optional| Description                      |
26| ------------| ---------| ---- | ---- | ------------------------- |
27| pid         | number   | No  | No| Process ID.                   |
28| bundleName  | string   | No  | No| Bundle name of the application.                 |
29| uid         | number   | No  | No|UID of the application.                 |
30| isContinuousTask | boolean   | No  | No| Whether the task is a continuous task. **true** if yes, **false** otherwise.                |
31| isKeepAlive      | boolean   | No  | No|Whether the process is a resident task. **true** if yes, **false** otherwise.                  |
32| state       | number   | No  |  No|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.    |
33
34**Example**
35```ts
36import { appManager } from '@kit.AbilityKit';
37
38let observerCode = appManager.on('applicationState', {
39  onForegroundApplicationChanged(appStateData) {
40    console.log(`onForegroundApplicationChanged, appStateData: ${JSON.stringify(appStateData)}.`);
41  },
42  onAbilityStateChanged(abilityStateData) {
43    console.log(`onAbilityStateChanged, abilityStateData: ${JSON.stringify(abilityStateData)}.`);
44  },
45  onProcessCreated(processData) {
46    console.log(`onProcessCreated, processData: ${JSON.stringify(processData)}.`);
47  },
48  onProcessDied(processData) {
49    console.log(`onProcessDied, processData: ${JSON.stringify(processData)}.`);
50  },
51  onProcessStateChanged(processData) {
52    console.log(`onProcessStateChanged, processData.pid : ${JSON.stringify(processData.pid)}.`);
53    console.log(`onProcessStateChanged, processData.bundleName : ${JSON.stringify(processData.bundleName)}.`);
54    console.log(`onProcessStateChanged, processData.uid : ${JSON.stringify(processData.uid)}.`);
55    console.log(`onProcessStateChanged, processData.isContinuousTask : ${JSON.stringify(processData.isContinuousTask)}.`);
56    console.log(`onProcessStateChanged, processData.isKeepAlive : ${JSON.stringify(processData.isKeepAlive)}.`);
57  },
58  onAppStarted(appStateData) {
59    console.log(`onAppStarted, appStateData: ${JSON.stringify(appStateData)}.`);
60  },
61  onAppStopped(appStateData) {
62    console.log(`onAppStopped, appStateData: ${JSON.stringify(appStateData)}.`);
63  }
64});
65```
66