• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.Ability (Ability Base Class)
2
3This is the base class of [UIAbility](js-apis-app-ability-uiAbility.md) and [ExtensionAbility](js-apis-app-ability-extensionAbility.md). It provides the callbacks for system configuration updates and memory level updates. You cannot inherit from this base class.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> The APIs of this module can be used only in the stage model.
9
10## Ability.onConfigurationUpdate
11
12onConfigurationUpdate(newConfig: Configuration): void;
13
14Called when the configuration of the environment where the ability is running is updated.
15
16**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
17
18**Parameters**
19
20| Name| Type| Mandatory| Description|
21| -------- | -------- | -------- | -------- |
22| newConfig | [Configuration](js-apis-app-ability-configuration.md) | Yes| New configuration.|
23
24**Example**
25  ```ts
26// You are not allowed to inherit from the top-level base class Ability. Therefore, the derived class UIAbility is used as an example.
27import UIAbility from '@ohos.app.ability.UIAbility';
28
29class MyUIAbility extends UIAbility {
30    onConfigurationUpdate(config) {
31        console.log('onConfigurationUpdate, config:' + JSON.stringify(config));
32    }
33}
34  ```
35
36## Ability.onMemoryLevel
37
38onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
39
40Called when the system adjusts the memory level.
41
42**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
43
44**Parameters**
45
46| Name| Type| Mandatory| Description|
47| -------- | -------- | -------- | -------- |
48| level | [AbilityConstant.MemoryLevel](js-apis-app-ability-abilityConstant.md#abilityconstantmemorylevel) | Yes| New memory level.|
49
50**Example**
51
52  ```ts
53// You are not allowed to inherit from the top-level base class Ability. Therefore, the derived class UIAbility is used as an example.
54import UIAbility from '@ohos.app.ability.UIAbility';
55
56class MyUIAbility extends UIAbility {
57    onMemoryLevel(level) {
58        console.log('onMemoryLevel, level:' + JSON.stringify(level));
59    }
60}
61  ```
62