For details about how to develop a service widget, see Form Kit Development Guide.
For details about the design specifications of service widgets, see Service Widget.
For details about how to implement service widget update, see Pushing a Widget Update Message.
Select a proper widget update mode to reduce the power consumption of service widget update.
To avoid power consumption caused by frequent widget updates, you are advised to select a proper scheduled update interval based on service requirements. Do not update widgets continuously and frequently even after the atomic service process is started.
The system determines whether a widget can be updated based on factors such as the widget visibility, entire device load, and widget update frequency.
Use the following methods to reduce the system resource usage of service widgets:
Design a proper information structure for widgets
Design a proper information structure for widgets based on their size, such as the number and layout of elements like controls, text, and images. Keep service widgets simple and easy to use to avoid complexity and system resource waste.
Avoid complex UI effects or interaction logic for widgets
You are advised not to use service widgets to implement high-frequency dynamic UI effects (such as GIF images, Swiper controls, and continuous high-frequency calls to the updateForm API).
Do not perform complex interactions within a widget. For example, users need to implement an operation by tapping a button and making a choice from the displayed level-2 option, or long-pressing or using multiple fingers.
Select image resources suitable for the current display device.
Do not use image resources whose resolution exceeds the screen resolution of the current device. Otherwise, memory and CPU resources will be wasted.
When using image resources, you should fully consider the image display dimensions and pixel density of the target device. For the actual display dimensions of a widget, see Dimensions and Basic Parameters.
Generally, image resources are provided based on the formula: DPI × Actual display width and height. To consider the display effect and precision, you can provide image resources based on the following formula:
Product of the image width and height <= Product of the actual display width and height × (Device pixel ratio^2)
The following table lists the formats of image resources. In addition, you can use formats such as WebP to provide resources.
Table 1 Suggestions on image resource formats
| Purpose | Suggestion |
|---|---|
| Displaying an animation | Preferentially use the attribute animation and frame animation capabilities provided by ArkUI to implement animation and dynamic effects. If the desired effect cannot be achieved, you can use GIF images. |
| Displaying an image | To balance the image resource size and display effect, you are advised to preferentially select JPEG images if the images do not have transparent attributes, and PNG images if the images have transparent attributes. |