harmony 鸿蒙Updating Widget Content

  • 2025-06-12
  • 浏览 (6)

Updating Widget Content

The ArkTS widget framework provides the updateForm API for widget providers and the requestForm API for widget hosts to proactively trigger widget page refreshes. It also alerts providers to update widgets based on the scheduled information.

In widget UI code, you can use LocalStorageProp to obtain the widget data that requires updating, sent by the provider

API System Capability Constraints
updateForm No 1. Invoked by the widget provider.
2. Allows only the widget provider to update its own widgets.
requestForm Yes 1. Invoked by the widget host.
2. Allows only the widget host to update the widgets added to it.

Widget provider proactively updating a widget

updateForm

If there is a need to update widget data, the widget provider, as long as it is running, can proactively update the widget using the updateForm API provided by formProvider.

Widget host proactively requesting a widget update

requestForm

If changes in system language or color scheme are detected, the widget host, as long as it is running, can proactively request to update the widget using the requestForm API provided by formHost. The widget manager then instructs the widget provider to complete the update.

Widget manager instructing the widget provider to periodically update a widget

timer_updateForm

Based on the scheduled update information configured by the widget provider, the widget manager determines whether to instruct the provider to update the widget, considering factors such as timing information, widget visibility status, and the number of updates.

The following are the typical use cases of widget updates:

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Form Kit

harmony 鸿蒙Configuring Widget Configuration Files

harmony 鸿蒙Updating Widget Content by Widget Host (for System Applications Only)

harmony 鸿蒙Creating an ArkTS Widget

harmony 鸿蒙Launching the UIAbility of the Widget Provider in the Background Through the call Event

harmony 鸿蒙Overview of ArkTs Widget Page Editing Interaction

harmony 鸿蒙Editing and Updating the Widget Content

harmony 鸿蒙Updating Widget Content Through the message Event

harmony 鸿蒙Widget Event Capability Overview

harmony 鸿蒙Launching the UIAbility of the Widget Provider Through the router Event

0  赞