1# @ohos.app.ability.appManager (appManager) 2 3The **appManager** module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory size of the application, and information about the running process. 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 9## Modules to Import 10 11```ts 12import { appManager } from '@kit.AbilityKit'; 13``` 14 15## ProcessState<sup>10+</sup> 16 17Enumerates the processes states. 18 19**Atomic service API**: This API can be used in atomic services since API version 11. 20 21**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22 23| Name | Value | Description | 24| -------------------- | --- | --------------------------------- | 25| STATE_CREATE | 0 | The process is being created. | 26| STATE_FOREGROUND | 1 | The process is running in the foreground. | 27| STATE_ACTIVE | 2 | The process is active. | 28| STATE_BACKGROUND | 3 | The process is running in the background. | 29| STATE_DESTROY | 4 | The process is being destroyed. | 30 31## appManager.isRunningInStabilityTest 32 33isRunningInStabilityTest(callback: AsyncCallback<boolean>): void 34 35Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result. 36 37**Atomic service API**: This API can be used in atomic services since API version 11. 38 39**System capability**: SystemCapability.Ability.AbilityRuntime.Core 40 41**Parameters** 42 43 | Name| Type| Mandatory| Description| 44 | -------- | -------- | -------- | -------- | 45 | callback | AsyncCallback<boolean> | Yes|Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite. | 46 47**Error codes** 48 49For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 50 51| ID| Error Message| 52| ------- | -------- | 53| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 54| 16000050 | Internal error. | 55 56**Example** 57 58```ts 59import { appManager } from '@kit.AbilityKit'; 60 61appManager.isRunningInStabilityTest((err, flag) => { 62 if (err) { 63 console.error(`isRunningInStabilityTest fail, err: ${JSON.stringify(err)}`); 64 } else { 65 console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`); 66 } 67}); 68``` 69 70 71## appManager.isRunningInStabilityTest 72 73isRunningInStabilityTest(): Promise<boolean> 74 75Checks whether this application is undergoing a stability test. This API uses a promise to return the result. 76 77**Atomic service API**: This API can be used in atomic services since API version 11. 78 79**System capability**: SystemCapability.Ability.AbilityRuntime.Core 80 81**Return value** 82 83 | Type| Description| 84 | -------- | -------- | 85 | Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.| 86 87**Error codes** 88 89For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 90 91| ID| Error Message| 92| ------- | -------- | 93| 16000050 | Internal error. | 94 95**Example** 96 97```ts 98import { appManager } from '@kit.AbilityKit'; 99import { BusinessError } from '@kit.BasicServicesKit'; 100 101appManager.isRunningInStabilityTest().then((flag) => { 102 console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`); 103}).catch((error: BusinessError) => { 104 console.error(`error: ${JSON.stringify(error)}`); 105}); 106``` 107 108 109## appManager.isRamConstrainedDevice 110 111isRamConstrainedDevice(): Promise\<boolean> 112 113Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result. 114 115**Atomic service API**: This API can be used in atomic services since API version 11. 116 117**System capability**: SystemCapability.Ability.AbilityRuntime.Core 118 119**Return value** 120 121 | Type| Description| 122 | -------- | -------- | 123 | Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.| 124 125**Error codes** 126 127For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 128 129| ID| Error Message| 130| ------- | -------- | 131| 16000050 | Internal error. | 132 133**Example** 134 135```ts 136import { appManager } from '@kit.AbilityKit'; 137import { BusinessError } from '@kit.BasicServicesKit'; 138 139appManager.isRamConstrainedDevice().then((data) => { 140 console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`); 141}).catch((error: BusinessError) => { 142 console.error(`error: ${JSON.stringify(error)}`); 143}); 144``` 145 146## appManager.isRamConstrainedDevice 147 148isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void 149 150Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result. 151 152**Atomic service API**: This API can be used in atomic services since API version 11. 153 154**System capability**: SystemCapability.Ability.AbilityRuntime.Core 155 156**Parameters** 157 158 | Name| Type| Mandatory| Description| 159 | -------- | -------- | -------- | -------- | 160 | callback | AsyncCallback<boolean> | Yes|Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite. | 161 162**Error codes** 163 164For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 165 166| ID| Error Message| 167| ------- | -------- | 168| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 169| 16000050 | Internal error. | 170 171**Example** 172 173```ts 174import { appManager } from '@kit.AbilityKit'; 175 176appManager.isRamConstrainedDevice((err, data) => { 177 if (err) { 178 console.error(`isRamConstrainedDevice fail, err: ${JSON.stringify(err)}`); 179 } else { 180 console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`); 181 } 182}); 183``` 184 185## appManager.getAppMemorySize 186 187getAppMemorySize(): Promise\<number> 188 189Obtains the memory size of this application. This API uses a promise to return the result. 190 191**Atomic service API**: This API can be used in atomic services since API version 11. 192 193**System capability**: SystemCapability.Ability.AbilityRuntime.Core 194 195**Return value** 196 197 | Type| Description| 198 | -------- | -------- | 199 | Promise<number> | Promise used to return the memory size, in MB. You can perform error processing or other custom processing based on the size. | 200 201**Error codes** 202 203For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 204 205| ID| Error Message| 206| ------- | -------- | 207| 16000050 | Internal error. | 208 209**Example** 210 211```ts 212import { appManager } from '@kit.AbilityKit'; 213import { BusinessError } from '@kit.BasicServicesKit'; 214 215appManager.getAppMemorySize().then((data) => { 216 console.log(`The size of app memory is: ${JSON.stringify(data)}`); 217}).catch((error: BusinessError) => { 218 console.error(`error: ${JSON.stringify(error)}`); 219}); 220``` 221 222## appManager.getAppMemorySize 223 224getAppMemorySize(callback: AsyncCallback\<number>): void 225 226Obtains the memory size of this application. This API uses an asynchronous callback to return the result. 227 228**Atomic service API**: This API can be used in atomic services since API version 11. 229 230**System capability**: SystemCapability.Ability.AbilityRuntime.Core 231 232**Parameters** 233 234 | Name| Type| Mandatory| Description| 235 | -------- | -------- | -------- | -------- | 236 | callback | AsyncCallback<number> | Yes|Callback used to return the memory size, in MB. You can perform error processing or other custom processing based on the size. | 237 238**Error codes** 239 240For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 241 242| ID| Error Message| 243| ------- | -------- | 244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 245| 16000050 | Internal error. | 246 247**Example** 248 249```ts 250import { appManager } from '@kit.AbilityKit'; 251 252appManager.getAppMemorySize((err, data) => { 253 if (err) { 254 console.error(`getAppMemorySize fail, err: ${JSON.stringify(err)}`); 255 } else { 256 console.log(`The size of app memory is: ${JSON.stringify(data)}`); 257 } 258}); 259``` 260 261## appManager.getRunningProcessInformation 262 263getRunningProcessInformation(): Promise\<Array\<ProcessInformation>> 264 265Obtains information about the running processes. This API uses a promise to return the result. 266 267> **NOTE** 268> 269> In versions earlier than API version 11, this API requires the **ohos.permission.GET_RUNNING_INFO** permission, which is available only for system applications. Since API version 11, no permission is required for calling this API. 270 271**Atomic service API**: This API can be used in atomic services since API version 11. 272 273**System capability**: SystemCapability.Ability.AbilityRuntime.Core 274 275**Return value** 276 277| Type| Description| 278| -------- | -------- | 279| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| 280 281**Error codes** 282 283For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 284 285| ID| Error Message| 286| ------- | -------- | 287| 16000050 | Internal error. | 288 289**Example** 290 291```ts 292import { appManager } from '@kit.AbilityKit'; 293import { BusinessError } from '@kit.BasicServicesKit'; 294 295appManager.getRunningProcessInformation().then((data) => { 296 console.log(`The running process information is: ${JSON.stringify(data)}`); 297}).catch((error: BusinessError) => { 298 console.error(`error: ${JSON.stringify(error)}`); 299}); 300``` 301 302## appManager.getRunningProcessInformation 303 304getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>>): void 305 306Obtains information about the running processes. This API uses an asynchronous callback to return the result. 307 308> **NOTE** 309> 310> In versions earlier than API version 11, this API requires the **ohos.permission.GET_RUNNING_INFO** permission, which is available only for system applications. Since API version 11, no permission is required for calling this API. 311 312**Atomic service API**: This API can be used in atomic services since API version 11. 313 314**System capability**: SystemCapability.Ability.AbilityRuntime.Core 315 316**Parameters** 317 318 | Name| Type| Mandatory| Description| 319 | -------- | -------- | -------- | -------- | 320 | callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Yes|Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| 321 322**Error codes** 323 324For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 325 326| ID| Error Message| 327| ------- | -------- | 328| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 329| 16000050 | Internal error. | 330 331**Example** 332 333```ts 334import { appManager } from '@kit.AbilityKit'; 335 336appManager.getRunningProcessInformation((err, data) => { 337 if (err) { 338 console.error(`getRunningProcessInformation fail, err: ${JSON.stringify(err)}`); 339 } else { 340 console.log(`The running process information is: ${JSON.stringify(data)}`); 341 } 342}); 343``` 344