0

In the the below medium article written by a Google Android Engineer, it states that the best way to fetch data in a glance widget is to use WorkManager.

The best way to fetch data asynchronously from the background is by using WorkManager and storing the data as recommended in the Guide to background work. The important part is to avoid launching new workers either consecutively (for example, inside GlanceAppWidgetReceiver.onUpdate) or when data is already loaded.

So how do you use WorkManager inside the content() function of GlanceAppWidget()? Can someone please provide a working example?

https://medium.com/androiddevelopers/demystifying-jetpack-glance-for-app-widgets-8fbc7041955c

mars8
  • 770
  • 1
  • 11
  • 25

2 Answers2

1

No official example yet, check this demo from Piotr

https://github.com/PiotrPrus/WeatherGlanceWidget/tree/main/app/src/main/java/app/piotrprus/weatherglancewidget/widget

Marcel
  • 2,094
  • 3
  • 23
  • 37
1

You could check this article where it demonstrates a practical example of how to schedule image downloading/displaying on a Glance widget with WorkManager

Astro
  • 376
  • 5
  • 11