• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @system.app (Application Context)
2
3> **NOTE**
4>
5> - The APIs of this module are no longer maintained since API version 7. You are advised to use the new APIs.
6>
7> - 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.
8
9
10## Modules to Import
11
12
13```
14import app from '@system.app';
15```
16
17
18## app.getInfo
19
20getInfo(): AppResponse
21
22Obtains the declared information in the **config.json** file of an application.
23
24> **NOTE**
25>
26> You are advised to use [@ohos.bundle](js-apis-Bundle.md) since API version 7.
27
28**System capability**: SystemCapability.ArkUI.ArkUI.Lite
29
30**Return value**
31
32| Type| Description|
33| -------- | -------- |
34| [AppResponse](#appresponse) | Application response information.|
35
36**Example**
37
38  ```
39  export default {
40    getInfo(){
41      var info = app.getInfo();
42        console.log(JSON.stringify(info));
43    }
44  }
45  ```
46
47## app.terminate
48
49terminate(): void
50
51Terminates the current ability.
52
53> **NOTE**
54>
55> You are advised to use [@ohos.ability.featureAbility](js-apis-ability-featureAbility.md) since API version 7.
56
57**System capability**: SystemCapability.ArkUI.ArkUI.Lite
58
59**Example**
60
61  ```
62  export default {
63    terminate(){
64      app.terminate();
65    }}
66  ```
67## app.requestFullWindow
68
69requestFullWindow(options?: RequestFullWindowOptions): void
70
71Requests 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.
72
73> **NOTE**
74>
75> You are advised to use [@ohos.window](js-apis-window.md) since API version 7.
76
77**System capability**: SystemCapability.ArkUI.ArkUI.Full
78
79**Parameters**
80
81| Name| Type| Mandatory| Description|
82| -------- | -------- | -------- | -------- |
83| 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.|
84
85**Example**
86
87  ```
88  export default {
89    requestFullWindow(){
90      app.requestFullWindow({
91        duration: 200});
92    }
93  }
94  ```
95
96## app.setImageCacheCount<sup>7+</sup>
97
98setImageCacheCount(value: number): void
99
100Sets 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.
101
102**System capability**: SystemCapability.ArkUI.ArkUI.Full
103
104**Parameters**
105
106| Name| Type| Mandatory| Description|
107| -------- | -------- | -------- | -------- |
108| value | number | Yes| Number of decoded images that are cached in the memory.|
109
110**Example**
111
112  ```
113  // app.ets
114  import app from '@system.app';
115
116  export default {
117      onCreate() {
118          app.setImageCacheCount(100)    // Set the maximum number of decoded images that can be cached in the memory to 100.
119          console.info('Application onCreate')
120      },
121      onDestroy() {
122          console.info('Application onDestroy')
123      },
124  }
125  ```
126
127## app.setImageRawDataCacheSize<sup>7+</sup>
128
129setImageRawDataCacheSize(value: number): void
130
131Sets 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.
132
133**System capability**: SystemCapability.ArkUI.ArkUI.Full
134
135**Parameters**
136
137| Name| Type| Mandatory| Description|
138| -------- | -------- | -------- | -------- |
139| value | number | Yes| Size of the image data cached before decoding, in bytes.|
140
141**Example**
142
143  ```
144  // app.ets
145  import app from '@system.app';
146
147  export default {
148      onCreate() {
149          app.setImageRawDataCacheSize(104857600)
150          // 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).
151          console.info('Application onCreate')
152      },
153      onDestroy() {
154          console.info('Application onDestroy')
155      },
156  }
157  ```
158
159## app.setImageFileCacheSize<sup>7+</sup>
160
161setImageFileCacheSize(value: number): void
162
163Sets 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 and thumbnails. 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.
164
165**System capability**: SystemCapability.ArkUI.ArkUI.Full
166
167**Parameters**
168
169| Name| Type| Mandatory| Description|
170| -------- | -------- | -------- | -------- |
171| value | number | Yes| Size of the image file cache, in bytes.|
172
173**Example**
174
175  ```
176  // app.ets
177  import app from '@system.app';
178
179  export default {
180      onCreate() {
181          app.setImageFileCacheSize(209715200)
182          // Set the upper limit of the image file cache to 200 MB. (200 x 1024 x 1024 B= 209715200 B = 200 MB).
183          console.info('Application onCreate')
184      },
185      onDestroy() {
186          console.info('Application onDestroy')
187      },
188  }
189  ```
190
191## AppResponse
192
193Defines the application response information.
194
195**System capability**: The items in the table below require different system capabilities. For details, see the table.
196
197| Name| Type| Mandatory| Description|
198| -------- | -------- | -------- |-------- |
199| appID<sup>6+</sup> | string | Yes| Bundle name of an application. It uniquely identifies the application.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Full|
200| appName | string | Yes| Application name.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|
201| versionName | string | Yes| Application version name.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|
202| versionCode | number | Yes| Application version number.<br> **System capability**: SystemCapability.ArkUI.ArkUI.Lite|
203
204## ScreenOnVisible<sup>(deprecated)</sup>
205
206screenOnVisible(options?: ScreenOnVisibleOptions):&nbsp;void
207
208Defines whether to keep the application visible when the screen is woken up.
209
210> **NOTE**
211>
212> This API is deprecated since API Version 8.
213
214**System capability**: SystemCapability.ArkUI.ArkUI.Full
215
216| Name| Type| Mandatory| Description|
217| -------- | -------- | -------- |-------- |
218| options | 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. |
219
220## ScreenOnVisibleOptions
221
222Defines the options of the visible interface on the screen.
223
224**System capability**: SystemCapability.ArkUI.ArkUI.Full
225
226| Name| Type| Mandatory| Description|
227| -------- | -------- | -------- | -------- |
228| visible | boolean | No| Whether to keep the application visible. The default value is **false**.|
229| success | () => void | No| Callback upon success.|
230| fail | (data: string, code: number) => void | No| Callback upon failure.|
231| complete | () => void | No| Called when the API call is complete.|
232
233## RequestFullWindowOptions
234
235Defines the options of the **RequestFullWindow** API.
236
237**System capability**: SystemCapability.ArkUI.ArkUI.Full
238
239| Name| Type| Mandatory| Description|
240| -------- | -------- | -------- | -------- |
241| duration | number | Yes| Duration of an animation, in milliseconds.|
242