• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AbilityStateData
2
3The **AbilityStateData** module defines the ability state information, which can be obtained through the **onAbilityStateChanged** lifecycle callback of [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md). The callback can be invoked after a lifecycle change listener is registered through [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver).
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    | Readable| Writable| Description                      |
22| ----------------------- | ---------| ---- | ---- | ------------------------- |
23| pid                     | number   | Yes  | No  | Process ID.                   |
24| bundleName              | string   | Yes  | No | Bundle name.         |
25| abilityName            | string   | Yes  | No  | Ability name.              |
26| uid                    | number   | Yes  | No  | User ID.                 |
27| state                   | number   | Yes  | No  | [Ability state](#ability-states).               |
28| moduleName<sup>9+</sup> | string   | Yes  | No  | Name of the HAP file to which the ability belongs.   |
29| abilityType | number | Yes  | No  | [Ability type](#ability-types), which can be **page** or **service**.|
30
31#### Ability States
32
33| Value  | State                      | Description                  |
34| ---- | -------------------------- | ---------------------- |
35| 0    | ABILITY_STATE_CREATE       | The ability is being created.     |
36| 1    | ABILITY_STATE_READY        | The ability has been created.     |
37| 2    | ABILITY_STATE_FOREGROUND   | The ability is running in the foreground.       |
38| 3    | ABILITY_STATE_FOCUS        | The ability has focus.       |
39| 4    | ABILITY_STATE_BACKGROUND   | The ability is running in the background.       |
40| 5    | ABILITY_STATE_TERMINATED   | The ability is terminated.       |
41| 8    | ABILITY_STATE_CONNECTED    | The background service is connected to the client.|
42| 9    | ABILITY_STATE_DISCONNECTED | The background service is disconnected from the client.|
43
44#### Ability Types
45
46| Value  | State   | Description                 |
47| ---- | ------- | --------------------- |
48| 0    | UNKNOWN | Unknown type.             |
49| 1    | PAGE    | Ability that has the UI.  |
50| 2    | SERVICE | Ability that provides the background service.|
51