A countdown widget looks simple: a number that goes down. But home-screen widgets are not tiny apps that run all the time. The system renders them on its own schedule, so a naive "update every second" approach does not work. Here is how countdowns stay correct on both platforms.
iOS: let the system draw the timer
WidgetKit widgets are built from a timeline of entries. You cannot push a new view every second, and you do not need to. Text has date styles that the system keeps live for you:
struct CountdownView: View { let departure: Date var body: some View { VStack { Text("Trip in") // Updates continuously without new timeline entries Text(departure, style: .relative) // Or a ticking clock: Text(departure, style: .timer) } } } The timeline then only needs an entry when something meaningful changes, such as "days" becoming "hours", or the trip starting:
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) { let now = Date() let entries = [Entry(date: now, departure: trip.departure), Entry(date: trip.departure, departure: trip.departure)] completion(Timeline(entries: entries, policy: .after(trip.departure))) } Android: the update period is not your clock
On Android, updatePeriodMillis in the widget's appwidget-provider XML has a minimum of 30 minutes, so it is useless for anything that changes by the minute. Two practical options:
- For a live ticking clock, use a
ChronometerinRemoteViewsand set it to count down (API 24+). - For a day count, schedule one update shortly after midnight with
AlarmManageror WorkManager, and recompute from the clock.
val views = RemoteViews(context.packageName, R.layout.countdown_widget) val base = SystemClock.elapsedRealtime() + (departureMillis - System.currentTimeMillis()) views.setChronometer(R.id.timer, base, null, true) views.setChronometerCountDown(R.id.timer, true) // API 24+ appWidgetManager.updateAppWidget(widgetId, views) Comparison
| iOS (WidgetKit) | Android (App Widgets) | |
|---|---|---|
| Live ticking | Text(date, style: .timer) | Chronometer + setChronometerCountDown |
| Day count | timeline entry per day | alarm or worker after midnight |
| Minimum system refresh | budgeted by the system | updatePeriodMillis ≥ 30 min |
| Golden rule | store the target date, never a counter | same |
The golden rule: store the date, not the number
Both platforms can kill and restore your widget at any time. If you store "12 days left" you will drift. Store the target date and time with its time zone, and compute the remaining time whenever you render.
Seeing it in a real app
We build Soon, a free vacation countdown app for iPhone and Android, and these rules are what keep its home-screen widget honest: a live countdown with a destination photo, plus a countdown on Apple Watch.
If you are building your own countdown, start with the date-style Text on iOS and a Chronometer on Android before reaching for background refresh. It saves battery and it is always on time.


