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