• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @system.app (Application Context)
2
3> **NOTE**
4>
5> The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
6
7
8## Modules to Import
9
10
11```ts
12import app, { AppResponse } from '@system.app'
13```
14
15## App
16
17### getInfo
18
19static getInfo(): AppResponse
20
21Obtains the declared information in the **config.json** file of an application.
22
23This API is deprecated since API version 9. You are advised to use [bundleManager.getApplicationInfo](../apis-ability-kit/js-apis-bundleManager.md#bundlemanagergetbundleinfoforself) instead.
24
25**Atomic service API**: This API can be used in atomic services since API version 12.
26
27**System capability**: SystemCapability.ArkUI.ArkUI.Lite
28
29**Return value**
30
31| Type | Description |
32| -------- | -------- |
33| [AppResponse](#appresponse) | Application response information. |
34
35**Example**
36
37```ts
38import app, { AppResponse } from '@system.app'
39export default class Info {
40  getInfo() {
41    let info:AppResponse = app.getInfo()
42    console.log(JSON.stringify(info))
43  }
44}
45```
46
47### terminate
48
49static terminate(): void
50
51Terminates the current ability.
52
53This API is deprecated since API version 7. You are advised to use [@ohos.ability.featureAbility](../apis-ability-kit/js-apis-ability-featureAbility.md) instead.
54
55**Atomic service API**: This API can be used in atomic services since API version 12.
56
57**System capability**: SystemCapability.ArkUI.ArkUI.Lite
58
59**Example**
60
61```ts
62import app, { AppResponse } from '@system.app'
63export default class TerM {
64  terminate() {
65    app.terminate()
66  }
67}
68```
69### setImageCacheCount<sup>7+</sup>
70
71static setImageCacheCount(value: number): void
72
73Sets the maximum number of decoded images that can be cached in the memory to speed up the loading of images from the same sources. If the input parameter is not set, the default value **0** is used, indicating that images are not cached. The built-in Least Recently Used (LRU) policy is used for caching. If the maximum number is exceeded, the images that have not been updated for the longest time will be removed. You are advised to set the parameter based on the application memory requirements. If the number of images is too large, the memory usage may be too high.
74
75**setImageCacheCount** takes effect only when used in [onPageShow](../apis-arkui/arkui-ts/ts-custom-component-lifecycle.md#onpageshow) or [aboutToAppear](../apis-arkui/arkui-ts/ts-custom-component-lifecycle.md#abouttoappear) on the page decorated by @Entry.
76
77**Atomic service API**: This API can be used in atomic services since API version 12.
78
79**System capability**: SystemCapability.ArkUI.ArkUI.Full
80
81**Parameters**
82
83| Name | Type | Mandatory | Description |
84| -------- | -------- | -------- | -------- |
85| value | number | Yes | Number of decoded images that are cached in the memory. |
86
87**Example**
88
89```ts
90// xxx.ets
91import app, { AppResponse } from '@system.app'
92
93@Entry
94@Component
95struct Index {
96  onPageShow() {
97    // Set the maximum number of decoded images that can be cached in the memory to 100.
98    app.setImageCacheCount(100)
99    console.info('Application onPageShow')
100  }
101  onDestroy() {
102    console.info('Application onDestroy')
103  }
104
105  build() {
106    Row(){
107      // xxxxxxxxxxxxx indicates the image address.
108      Image('xxxxxxxxxxxxx')
109        .width(200)
110        .height(50)
111    }.width('100%')
112  }
113}
114```
115
116### setImageRawDataCacheSize<sup>7+</sup>
117
118static setImageRawDataCacheSize(value: number): void
119
120Sets the maximum size (in bytes) of the image data cached in the memory before decoding to speed up the loading of images from the same sources. If the input parameter is not set, the default value **0** is used, indicating that images are not cached. The LRU policy is used for caching. If the maximum size is exceeded, the images that have not been updated for the longest time will be removed. You are advised to set the parameter based on the application memory requirements. If the image cache is too large, the memory usage may be too high.
121
122**setImageRawDataCacheSize** takes effect only when used in [onPageShow](../apis-arkui/arkui-ts/ts-custom-component-lifecycle.md#onpageshow) or [aboutToAppear](../apis-arkui/arkui-ts/ts-custom-component-lifecycle.md#abouttoappear) on the page decorated by @Entry.
123
124**Atomic service API**: This API can be used in atomic services since API version 12.
125
126**System capability**: SystemCapability.ArkUI.ArkUI.Full
127
128**Parameters**
129
130| Name | Type | Mandatory | Description |
131| -------- | -------- | -------- | -------- |
132| value | number | Yes | Size of the image data cached before decoding, in bytes. |
133
134**Example**
135
136```ts
137// xxx.ets
138import app, { AppResponse } from '@system.app'
139
140@Entry
141@Component
142struct Index {
143  onPageShow() {
144    // Set the upper limit of the memory for caching image data before decoding to 100 MB. (100 x 1024 x 1024 B =104857600 B = 100 MB).
145    app.setImageRawDataCacheSize(104857600)
146    console.info('Application onPageShow')
147  }
148  onDestroy() {
149    console.info('Application onDestroy')
150  }
151
152  build() {
153    Row(){
154      // xxxxxxxxxxxxx indicates the image address.
155      Image('xxxxxxxxxxxxx')
156        .width(200)
157        .height(50)
158    }.width('100%')
159  }
160}
161```
162
163### setImageFileCacheSize<sup>7+</sup>
164
165static setImageFileCacheSize(value: number): void
166
167Sets the maximum size of the image file cache (in bytes) to speed up the loading of images from the same sources, especially online image sources. If the input parameter is not set, the default value 100 MB is used. The LRU policy is used for caching. If the maximum size is exceeded, the images that have not been updated for the longest time will be removed. You are advised to set the parameter based on the application memory requirements. If the image cache is too large, the disk usage may be too high.
168
169**Atomic service API**: This API can be used in atomic services since API version 12.
170
171**System capability**: SystemCapability.ArkUI.ArkUI.Full
172
173**Parameters**
174
175| Name | Type | Mandatory | Description |
176| -------- | -------- | -------- | -------- |
177| value | number | Yes | Size of the image file cache, in bytes. |
178
179**Example**
180
181```ts
182// app.ets
183import app, { AppResponse } from '@system.app'
184
185export default class OnC {
186  onCreate() {
187    app.setImageFileCacheSize(209715200)
188    // Set the upper limit of the image file cache to 200 MB. (200 x 1024 x 1024 B= 209715200 B = 200 MB).
189    console.info('Application onCreate')
190  }
191  onDestroy() {
192    console.info('Application onDestroy')
193  }
194}
195```
196
197### ScreenOnVisible<sup>(deprecated)</sup>
198
199static screenOnVisible(options?: ScreenOnVisibleOptions): void
200
201Defines whether to keep the application visible when the screen is woken up.
202
203This API is deprecated since API version 8.
204
205**System capability**: SystemCapability.ArkUI.ArkUI.Full
206
207| Name   | Type                                             | Mandatory | Description                                                        |
208| ------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
209| options | [ScreenOnVisibleOptions](#screenonvisibleoptions) | No  | With keep-alive, the system is prevented from returning to the home screen when the screen is locked, so that the application is visible when the screen is woken up. |
210
211### requestFullWindow<sup>(deprecated)</sup>
212
213static requestFullWindow(options?: RequestFullWindowOptions): void
214
215Requests the application to run in full window. You can call this API when the FA runs in a non-full window, for example, semi-modal FA. This API is invalid for an application already in full-window mode.
216
217You are advised to use [@ohos.window](js-apis-window.md) since API version 7.
218
219**System capability**: SystemCapability.ArkUI.ArkUI.Full
220
221**Parameters**
222
223| Name | Type                                                 | Mandatory | Description                                                        |
224| ------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
225| options | [RequestFullWindowOptions](#requestfullwindowoptions) | No  | Duration for transition from the non-full window to the full window, in milliseconds. By default, the value is in direct proportion to the distance between the non-full window and the full window. |
226
227**Example**
228
229```ts
230import app, { AppResponse } from '@system.app'
231export default class Req {
232  requestFullWindow() {
233    app.requestFullWindow({
234      duration: 200
235    })
236  }
237}
238```
239
240## AppResponse
241
242Defines the application response information.
243
244**Atomic service API**: This API can be used in atomic services since API version 12.
245
246**System capability**: The items in the table below require different system capabilities. For details, see the table.
247
248| Name | Type | Mandatory | Description |
249| -------- | -------- | -------- |-------- |
250| appID<sup>6+</sup> | string | Yes | Bundle name of an application. It uniquely identifies the application.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Full|
251| appName | string | Yes | Application name.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|
252| versionName | string | Yes | Application version name.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|
253| versionCode | number | Yes | Application version number.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|
254
255## ScreenOnVisibleOptions
256
257Defines the options of the visible interface on the screen.
258
259**System capability**: SystemCapability.ArkUI.ArkUI.Full
260
261| Name | Type | Mandatory | Description |
262| -------- | -------- | -------- | -------- |
263| visible | boolean | No | Whether to keep the application visible. The default value is **false**. |
264| success | () => void | No | Callback upon success. |
265| fail | (data: string, code: number) => void | No | Callback upon failure. |
266| complete | () => void | No | Called when the API call is complete. |
267
268## RequestFullWindowOptions
269
270Defines the options of the **RequestFullWindow** API.
271
272**System capability**: SystemCapability.ArkUI.ArkUI.Full
273
274| Name | Type | Mandatory | Description |
275| -------- | -------- | -------- | -------- |
276| duration | number | Yes | Duration of an animation, in milliseconds. |
277