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>
11> The APIs of this module can be used only in the stage model.
12
13## Modules to Import
14
15```ts
16import { AbilityStage } from '@kit.AbilityKit';
17```
18
19## AbilityStage.onCreate
20
21onCreate(): void
22
23Called when the application is created.
24
25**Atomic service API**: This API can be used in atomic services since API version 11.
26
27**System capability**: SystemCapability.Ability.AbilityRuntime.Core
28
29**Example**
30
31```ts
32import { AbilityStage } from '@kit.AbilityKit';
33
34class MyAbilityStage extends AbilityStage {
35  onCreate() {
36    console.log('MyAbilityStage.onCreate is called');
37  }
38}
39```
40
41
42## AbilityStage.onAcceptWant
43
44onAcceptWant(want: Want): string
45
46Called when a specified ability is started.
47
48**Atomic service API**: This API can be used in atomic services since API version 11.
49
50**System capability**: SystemCapability.Ability.AbilityRuntime.Core
51
52**Parameters**
53
54| Name| Type| Mandatory| Description|
55| -------- | -------- | -------- | -------- |
56| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.|
57
58**Return value**
59
60  | Type| Description|
61  | -------- | -------- |
62  | string | Ability ID. If the ability with this ID 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.|
63
64**Example**
65
66```ts
67import { AbilityStage, Want } from '@kit.AbilityKit';
68
69class MyAbilityStage extends AbilityStage {
70  onAcceptWant(want: Want) {
71    console.log('MyAbilityStage.onAcceptWant called');
72    return 'com.example.test';
73  }
74}
75```
76
77## AbilityStage.onNewProcessRequest<sup>11+</sup>
78
79onNewProcessRequest(want: Want): string
80
81Called when the UIAbility is started in the specified process.
82
83**System capability**: SystemCapability.Ability.AbilityRuntime.Core
84
85**Parameters**
86
87| Name| Type| Mandatory| Description|
88| -------- | -------- | -------- | -------- |
89| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.|
90
91**Return value**
92
93| Type| Description|
94| -------- | -------- |
95| string | Custom process identifier. If the process with this identifier has been created, the ability runs in the process. Otherwise, a new process is created and the ability runs in it.|
96
97**Example**
98
99```ts
100import { AbilityStage, Want } from '@kit.AbilityKit';
101
102class MyAbilityStage extends AbilityStage {
103  onNewProcessRequest(want: Want) {
104    console.log('MyAbilityStage.onNewProcessRequest called');
105    return 'com.example.test';
106  }
107}
108```
109
110
111## AbilityStage.onConfigurationUpdate
112
113onConfigurationUpdate(newConfig: Configuration): void
114
115Called when the global configuration is updated.
116
117**Atomic service API**: This API can be used in atomic services since API version 11.
118
119**System capability**: SystemCapability.Ability.AbilityRuntime.Core
120
121**Parameters**
122
123  | Name| Type| Mandatory| Description|
124  | -------- | -------- | -------- | -------- |
125  | 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.|
126
127**Example**
128
129```ts
130import { AbilityStage, Configuration } from '@kit.AbilityKit';
131
132class MyAbilityStage extends AbilityStage {
133  onConfigurationUpdate(config: Configuration) {
134    console.log(`onConfigurationUpdate, language: ${config.language}`);
135  }
136}
137```
138
139## AbilityStage.onMemoryLevel
140
141onMemoryLevel(level: AbilityConstant.MemoryLevel): void
142
143Called 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.
144
145**Atomic service API**: This API can be used in atomic services since API version 11.
146
147**System capability**: SystemCapability.Ability.AbilityRuntime.Core
148
149**Parameters**
150
151  | Name| Type| Mandatory| Description|
152  | -------- | -------- | -------- | -------- |
153  | level | [AbilityConstant.MemoryLevel](js-apis-app-ability-abilityConstant.md#memorylevel) | 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.|
154
155**Example**
156
157```ts
158import { AbilityStage, AbilityConstant } from '@kit.AbilityKit';
159
160class MyAbilityStage extends AbilityStage {
161  onMemoryLevel(level: AbilityConstant.MemoryLevel) {
162    console.log(`onMemoryLevel, level: ${JSON.stringify(level)}`);
163  }
164}
165```
166
167## AbilityStage.context
168
169context: AbilityStageContext
170
171Defines the context of **AbilityStage**.
172
173**Atomic service API**: This API can be used in atomic services since API version 11.
174
175**System capability**: SystemCapability.Ability.AbilityRuntime.Core
176
177| Name     | Type                       | Description                                                        |
178| ----------- | --------------------------- | ------------------------------------------------------------ |
179| context  | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | The context is obtained in the callback invoked when initialization is performed during ability startup.|
180
181**Example**
182
183```ts
184import { AbilityStage } from '@kit.AbilityKit';
185
186export default class MyAbilityStage extends AbilityStage {
187  onCreate() {
188    let abilityStageContext = this.context;
189  }
190}
191```
192
193## AbilityStage.onDestroy<sup>12+<sup>
194
195onDestroy(): void
196
197Called when the application is destroyed. This API is called during the normal lifecycle. If the application exits abnormally or is terminated, this API is not called.
198
199**Atomic service API**: This API can be used in atomic services since API version 12.
200
201**System capability**: SystemCapability.Ability.AbilityRuntime.Core
202
203**Example**
204
205```ts
206import { AbilityStage } from '@kit.AbilityKit';
207
208class MyAbilityStage extends AbilityStage {
209  onDestroy() {
210    console.log('MyAbilityStage.onDestroy is called');
211  }
212}
213```
214