The Ability class is the fundamental unit for application lifecycle scheduling. It is the base class of UIAbility and ExtensionAbility, and provides callbacks for system configuration updates and memory level updates. However, you cannot inherit directly from this base class. You should opt for either UIAbility or ExtensionAbility based on your service needs. For details, see Introduction to Ability Kit.
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.
The APIs of this module can be used only in the stage model.
The following figure shows the inheritance relationship of the Ability base class and its child classes.
Some ExtensionAbility components (such as FormExtensionAbility and InputMethodExtensionAbility) do not inherit from the ExtensionAbility base class and therefore are not provided in the following figure.

onConfigurationUpdate(newConfig: Configuration): void
Called when a system environment variable changes. You can override this callback to respond to changes in the system environment variables. For example, when the system language changes, the application can perform customized processing in the callback.
This callback is subject to certain restrictions when actually triggered. For example, if you set the application language through setLanguage, the system no longer triggers the onConfigurationUpdate callback even if the system language changes. For details, see Usage Scenario.
To monitor the environment variables of the Ability on a page, use ApplicationContext.on('environment').
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.Ability.AbilityRuntime.AbilityCore
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| newConfig | Configuration | Yes | New configuration. |
Example
// You are not allowed to inherit from the top-level base class Ability. Therefore, the derived class UIAbility is used as an example.
import { UIAbility, Configuration } from '@kit.AbilityKit';
class MyUIAbility extends UIAbility {
onConfigurationUpdate(config: Configuration) {
console.info(`onConfigurationUpdate, config: ${JSON.stringify(config)}`);
}
} onMemoryLevel(level: AbilityConstant.MemoryLevel): void
Called when the available memory of the entire device changes to a specified level. You can override this callback to respond to changes in the memory level, for example, releasing cached data.
The onMemoryLevel callback runs on the main thread of the current process. If you release UI components that take a long time in this callback, the main thread tasks will be blocked. Therefore, releasing UI components in this callback is not recommended.
To monitor the environment variables of the Ability on a page, use ApplicationContext.on('environment').
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.Ability.AbilityRuntime.AbilityCore
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| level | AbilityConstant.MemoryLevel | Yes | Memory level of the entire device. For the corresponding trigger scenarios, see AbilityConstant.MemoryLevel. |
Example
// You are not allowed to inherit from the top-level base class Ability. Therefore, the derived class UIAbility is used as an example.
import { UIAbility, AbilityConstant } from '@kit.AbilityKit';
class MyUIAbility extends UIAbility {
onMemoryLevel(level: AbilityConstant.MemoryLevel) {
console.info(`onMemoryLevel, level: ${JSON.stringify(level)}`);
}
}