目录

Passive Update of ArkTS Widgets

This section provides the development guidelines for passive update. For details about the update process, see Passive Update.

Interval-based Update

Form Kit provides the following methods for interval-based update:

After an interval-based or next update is triggered, the system calls the onUpdateForm lifecycle callback of FormExtensionAbility. In this callback, you can use the updateForm API to refresh the widget content. For details about the onUpdateForm lifecycle callback, see Managing ArkTS Widget Lifecycle.

Constraints

  1. Each widget can be updated at the specified interval for a maximum of 50 times every day, including updates triggered by modifying the updateDuration field or calling setFormNextRefreshTime. When the limit is reached, the widget cannot be updated in this mode again. The number of update times is reset at 00:00 every day.
  2. A single timer is used for interval-based updates. Therefore, if a widget is configured to update at specified intervals, the first update may have a maximum deviation of 30 minutes. For example, if widget A (updated every half an hour) is added at 03:20 and widget B (also updated every half an hour) is added at 03:40, the first update of widget B has a deviation of 10 minutes to the expected time: The timer starts at 03:20 when widget A is added, triggers an update for widget A at 03:50, and triggers another update for widget B at 04:20 (instead of 04:10 as expected).
  3. Interval-based updates are triggered only when the widget is visible. If the widget is invisible, the update action and data are recorded. The layout is refreshed once the widget becomes visible.
  4. Before API version 26.0.0, when widget proxy update is enabled, interval-based update and next update do not take effect. Starting from API version 26.0.0, widget proxy update, interval-based update, and next update can take effect simultaneously.

Time-specific Update

Form Kit provides the following methods for time-specific widget update:

After a time-specific update is triggered, the system calls the onUpdateForm lifecycle callback of FormExtensionAbility. In this callback, you can use the updateForm API to refresh the widget content. For details about the onUpdateForm lifecycle callback, see Managing ArkTS Widget Lifecycle.

  • If both interval-based update (updateDuration) and time-specific update (scheduledUpdateTime) are configured, the interval-based update takes precedence, and the time-specific update will not be executed. To enable time-specific updates, set updateDuration to 0.
  • A maximum of 24 times can be set for multiScheduledUpdateTime.
  • If both update at a single time and update at multiple times are configured, only the update at multiple times takes effect.
  • To ensure forward compatibility, retain the scheduledUpdateTime field.

Constraints

  1. Time-specific updates are triggered only when the widget is visible. If the widget is invisible, the update action and data are recorded. The layout is refreshed once the widget becomes visible.

Conditional Update

Form Kit provides the following methods for conditional updates:

  • A widget update is triggered when the device transitions from a no-network state to a connected state. However, an update is not triggered when a user switches between networks (for example, switching between different Wi-Fi networks or between Wi-Fi and cellular data) or goes from Internet connection to no Internet connection.

  • To minimize the frequency of widget process initiations during frequent network on/off scenarios, a no-network condition is determined after the network has been continuously unavailable for 10 minutes. Upon reconnection, a network-based update is then triggered.

{
  "forms": [
    {
      "name": "UpdateDuration",
      "description": "$string:widget_updateduration_desc",
      "src": "./ets/updateduration/pages/UpdateDurationCard.ets",
      "uiSyntax": "arkts",
      "window": {
        "designWidth": 720,
        "autoDesignWidth": true
      },
      "isDefault": true,
      "updateEnabled": true,
      "scheduledUpdateTime": "10:30",
      "updateDuration": 2,
      "defaultDimension": "2*2",
      "supportDimensions": [
        "2*2"
      ],
      "conditionUpdate": [
        "network"
      ]
    }
  ]
}