• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.AbilityStage (AbilityStage)
2
3**AbilityStage** is a runtime class for HAP files.
4
5**AbilityStage** notifies you of when you can perform HAP initialization such as resource pre-loading and thread creation during the HAP loading.
6
7> **NOTE**
8>
9> 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.
10> The APIs of this module can be used only in the stage model.
11
12## Modules to Import
13
14```ts
15import AbilityStage from '@ohos.app.ability.AbilityStage';
16```
17
18## AbilityStage.onCreate
19
20onCreate(): void
21
22Called when the application is created.
23
24**System capability**: SystemCapability.Ability.AbilityRuntime.Core
25
26**Example**
27
28```ts
29import AbilityStage from '@ohos.app.ability.AbilityStage';
30
31class MyAbilityStage extends AbilityStage {
32    onCreate() {
33        console.log('MyAbilityStage.onCreate is called');
34    }
35}
36```
37
38
39## AbilityStage.onAcceptWant
40
41onAcceptWant(want: Want): string;
42
43Called when a specified ability is started.
44
45**System capability**: SystemCapability.Ability.AbilityRuntime.Core
46
47**Parameters**
48
49| Name| Type| Mandatory| Description|
50| -------- | -------- | -------- | -------- |
51| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.|
52
53**Return value**
54
55  | Type| Description|
56  | -------- | -------- |
57  | string | Returns an ability ID. If this ability has been started, no new instance is created and the ability is placed at the top of the stack. Otherwise, a new instance is created and started.|
58
59**Example**
60
61```ts
62import AbilityStage from '@ohos.app.ability.AbilityStage';
63
64class MyAbilityStage extends AbilityStage {
65    onAcceptWant(want) {
66        console.log('MyAbilityStage.onAcceptWant called');
67        return 'com.example.test';
68    }
69}
70```
71
72
73## AbilityStage.onConfigurationUpdate
74
75onConfigurationUpdate(newConfig: Configuration): void;
76
77Called when the global configuration is updated.
78
79**System capability**: SystemCapability.Ability.AbilityRuntime.Core
80
81**Parameters**
82
83  | Name| Type| Mandatory| Description|
84  | -------- | -------- | -------- | -------- |
85  | newConfig | [Configuration](js-apis-app-ability-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.|
86
87**Example**
88
89```ts
90import AbilityStage from '@ohos.app.ability.AbilityStage';
91
92class MyAbilityStage extends AbilityStage {
93    onConfigurationUpdate(config) {
94        console.log('onConfigurationUpdate, language:' + config.language);
95    }
96}
97```
98
99## AbilityStage.onMemoryLevel
100
101onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
102
103Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.
104
105**System capability**: SystemCapability.Ability.AbilityRuntime.Core
106
107**Parameters**
108
109  | Name| Type| Mandatory| Description|
110  | -------- | -------- | -------- | -------- |
111  | level | [AbilityConstant.MemoryLevel](js-apis-app-ability-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.|
112
113**Example**
114
115```ts
116import AbilityStage from '@ohos.app.ability.AbilityStage';
117
118class MyAbilityStage extends AbilityStage {
119    onMemoryLevel(level) {
120        console.log('onMemoryLevel, level:' + JSON.stringify(level));
121    }
122}
123```
124
125## AbilityStage.context
126
127context: AbilityStageContext;
128
129Defines the context of **AbilityStage**.
130
131**System capability**: SystemCapability.Ability.AbilityRuntime.Core
132
133| Name     | Type                       | Description                                                        |
134| ----------- | --------------------------- | ------------------------------------------------------------ |
135| context  | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | The context is obtained in the callback invoked when initialization is performed during ability startup.|
136