Fix weather widget stuck in loading state - #431
Open
ar9988 wants to merge 1 commit into
Open
Conversation
ar9988
requested review from
alabiaga,
ashnohe,
madebymozart and
yrezgui
as code owners
August 19, 2026 09:36
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Investigates #402 —
WeatherGlanceWidgetgets stuck in the loading state (WeatherInfo.Loading) after following the "Always install with package manager" + "Launch: Nothing" run configuration from the sample's README.Root cause
WeatherGlanceWidgetReceiver.onEnabled()callsWeatherRepo.updateWeatherInfo()to populate the initial weather state. However,onEnabled()is only called once, when the number of widget instances for this provider goes from 0 to 1.When the app process is restarted while a widget instance already exists on the home screen,
onEnabled()is not invoked again because the widget provider already has an active instance. The widget is still updated and rendered through the normal Glance update flow (onUpdate→provideGlance), but sinceWeatherRepo's state is held in memory and resets on process restart, nothing re-triggers the data fetch — so the widget keeps rendering theLoadingstate it was left with.This is confirmed by logcat: in the broken case,
WeatherRepo: updateWeatherInfo callednever appears, whileonUpdateandprovideGlancestill run normally.Fix
Move the data-loading call out of the
Receiverlifecycle callbacks and intoprovideGlance(), per theGlanceAppWidget.provideGlancedocumentation:CoroutineScope(Dispatchers.IO).launch { WeatherRepo.updateWeatherInfo() }calls fromonEnabled()andonUpdate().provideGlance()provides the appropriate entry point to load data required to render the widget before callingprovideContent().WeatherRepo.updateWeatherInfo()already has its own throttling (mutex+lastRun/TIMEOUT), preventing redundant updates when multiple widget instances trigger the call.Testing
On a Pixel 7 emulator running API 30 (Android 11), I reproduced the bug using the run configuration described in the sample's README (Always install with package manager + Launch: Nothing). Logcat confirmed that
updateWeatherInfowas never called and the widget stayed inLoading.After the fix, on the same environment, I verified across multiple runs that:
provideGlance→updateWeatherInfo()→provideContentexecutes correctly on every relaunch, without requiring a resize.LoadingtoAvailableas expected.updateWeatherInfo - throttled (too soon)logs).Note
I also tested the fix on API 37 (Android 16) and on a physical Samsung device. In both environments, the issue still reproduces. Further investigation is needed to determine whether the issue has a different cause in these environments.