android / android/platform-samples

[Bug]: WeatherGlanceWidget not reloading after relaunch

Open
#402 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Kotlin
Stars
1.7k
Forks
541
Avg merge
7d 23h
Merged PRs (30d)
3

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### In which area is the issue?

User Interface

### In a specific sample?

WeatherGlanceWidget.kt

### What happened?

https://github.com/android/platform-samples/blob/main/samples/user-interface/appwidgets/README.md says:

> Run a new configuration
> When creating a new run configuration, it's important to ensure that the widget is recreated without launching a new activity. Follow these steps to do so:
> In Android Studio, select Run > Edit Configurations.
> In the Run/Debug Configurations dialog, select Always install with package manager....
> Under Launch Options, in the Launch menu, select Nothing.
> This will ensure that the widget is recreated but no activity is launched.

But when I follow these steps, after adding `WeatherGlanceWidget`, every time I relaunch the app from Android Studio, the widget displays the `@layout/glance_default_loading_layout` and `WeatherGlanceWidget.provideGlance()` is never called.

If I resize the widget, then `provideGlance()` is finally called, but it displays only the `WeatherInfo.Loading` state, never `WeatherInfo.Available`/`WeatherInfo.Unavailable`.

https://github.com/user-attachments/assets/9b5cba4c-954d-4f59-9981-767ab29ebb38

### Relevant logcat output

```shell
[Run 'app' clicked]
---------------------------- PROCESS ENDED (25711) for package com.example.platform ----------------------------
---------------------------- PROCESS STARTED (26122) for package com.example.platform ----------------------------
(this time initial layout was replaced with glance composable loading state)
[Run 'app' clicked]
---------------------------- PROCESS ENDED (26122) for package com.example.platform ----------------------------
---------------------------- PROCESS STARTED (26595) for package com.example.platform ----------------------------
---------------------------- PROCESS ENDED (26595) for package com.example.platform ----------------------------
(this time initial layout is kept forever)
```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start with samples/user-interface/appwidgets/README.md and WeatherGlanceWidget.kt, then reproduce the Android Studio configuration described in the issue while watching the provided logcat sequence. Trace when provideGlance() is called and how the widget moves beyond its loading state; done means relaunching recreates the widget and it reaches the expected Available or Unavailable state.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.