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
No official example yet, check this demo from Piotr
https://github.com/PiotrPrus/WeatherGlanceWidget/tree/main/app/src/main/java/app/piotrprus/weatherglancewidget/widget