
I built a widget because I was tired of opening an app to read one number. It sat on my home screen, it looked right, and for a week I trusted it. Then I noticed the number was wrong by a wide margin, and it had been wrong for a while. Nothing on the screen said the value was stale.
That is the part nobody warns you about. A widget does not look stale, and it does not fade or grey out on its own. It shows whatever it last wrote, with the same confidence it had on the first frame after a fresh update.
The refresh interval was never mine to set
My first assumption was that I had picked the wrong interval. I had written the update code, so I assumed I controlled its schedule. I went looking for a much smaller number. That turned out to be the wrong place to look.
Android schedules periodic work through WorkManager, and a PeriodicWorkRequest has a floor of 15 minutes. It is not a default you can lower. It is not a suggestion you can talk your way around. You can ask for something faster than that floor. The system will quietly hand you the minimum it allows instead. Your code and your intent drift apart, and no error shows up to warn you.
Fifteen minutes is a long time when the thing you are watching changes every few seconds. I spent a couple of evenings trying to close that gap with a foreground service. That worked, and it cost battery in a way I was not willing to defend, which is a separate story.
The root problem is not the tool
The useful correction came when I stopped asking how to refresh faster. The real question was why the widget had no way to be honest about its age. If a value can be 15 minutes old, then the value needs a timestamp next to it. That is a design problem, not a scheduling problem.
Once I framed it that way, the fix stopped being clever. The widget shows the number it has, plus a small line underneath that reads how long ago it was written. When that age passes 20 minutes, the label turns amber. Amber is not a warning that something broke. It is a plain statement that what you are reading may no longer be true.
I picked 20 minutes on purpose, and the margin is the point. It is a bit longer than the 15-minute floor, so a healthy widget almost never turns amber. If it does turn amber, something in the chain is genuinely stuck, and that is information I want.
What I had to give up in the layout
The widget toolkit I used was Glance, the Compose-style layer for app widgets, and it is much smaller than the Compose you get inside an activity. There is no weight modifier for splitting space between children. There is no SpaceBetween arrangement for pushing children apart. Gradients are not available the way you expect, and a Button cannot be styled freely.
That matters because my first design put a price on the left and a percent change on the right. I wanted them pushed apart, with a soft gradient behind them. None of it survived contact with the real API. I rebuilt the layout with fixed padding and a single vertical column, and honestly it reads better now. The constraint did me a favour, but only after I stopped fighting it.
One rule I keep: do not stack lists in a widget. Two lines of text and one small label is about the limit. A 4x2 area cannot carry much more without looking crowded.
The two extra refreshes that did help
Static periodic updates alone felt lifeless, so I added two triggers that cost almost nothing. Both of them are honest, in the sense that they update the data rather than pretending the old data is new.
- When the screen turns on, the widget asks for a fresh value if the current one is older than the interval.
- When the app itself is opened, the widget is updated immediately after the app finishes its own fetch.
Together they make the widget feel current during the moments I actually look at it, which is the morning and the evening. Between those moments it sits still, and that is fine, because the label says so.
What this does not fix
I want to be clear about the limits of this design. There is no data yet on battery cost. I never ran a clean comparison between the periodic version and the foreground service. What I can say is that the service is gone. The phone no longer warms up in my pocket during a long walk, which is an observation rather than a measurement.
Amber also does not tell you why the data is old. It could be that the phone was in deep sleep. It could be that the app was force-stopped, or that the request failed three times in a row. The label reports age, not cause, and I have not found a way to compress a cause into four characters without lying.
The last honest limitation is that the 15-minute floor is a platform decision, not a law of nature. It has changed before, and it can change again with any Android release. A widget built around a hardcoded interval will keep working and quietly become less honest the day that number moves.
So the widget still cannot be real-time, and I no longer pretend it is. It refreshes on the platform's schedule, it admits its age, and it stays quiet in between. That is a smaller promise than the one I started with, and it is the first version I actually trust. How do you handle a screen that has to show a number it cannot keep current?
Cover photo: Océanos y dados, CC0, via Wikimedia Commons.
