MB·07
Background Work, Push and Battery
Doing work when the app isn't on screen without draining the battery or being killed for it: how the cellular radio spends energy (wake-up, tail time) and why many small transfers cost more than one large one, Android's Doze, App Standby buckets and WorkManager, iOS's background modes and BGTaskScheduler, push notifications end to end (tokens, FCM and APNs, priorities, collapse keys, expiry, channels and permissions), live delivery tracking with Live Activities and ongoing notifications, and location; with a lab that models an hour of radio use for polling, chatty analytics and batched work with push.
Start here: the battery is a shared budget
Users judge apps by battery impact, and both platforms enforce it: Android's Doze and App Standby defer background work of apps the user isn't using; iOS suspends apps in the background and runs background tasks only when it decides it's a good time. An app that fights these rules gets its work delayed, killed, or flagged in battery settings, and gets uninstalled.
The biggest battery cost of most apps isn't the CPU: it's the cellular radio. Waking it costs energy, and after each transfer it stays in a high-power state for several seconds (the tail) in case more data follows. Many small transfers spread out over time keep the radio awake far more than their bytes suggest.
An hour of radio, modelled
Using typical published LTE behaviour (≈ 1 W while active or in its ~10 s tail, ≈ 0.02 W idle; these are assumptions, real values vary):
| App behaviour | Radio in high power per hour | Energy per hour |
|---|---|---|
| idle (nothing sent) | 0 | 20 mWh |
| analytics event sent every 60 s | 10.5 min | 193 mWh |
| order status polled every 30 s | 21 min | 366 mWh |
| both, at unaligned times | 31.5 min | 539 mWh (~3% of a phone battery per hour) |
| events batched every 15 min, order status by push | 1.4 min | 43 mWh |
Same information, 12× less energy: batch what can wait, push what can't, and never poll in the background.
How deep to go
Volume 17 defines six mastery levels. For background work and push:
| Level | What you can do |
|---|---|
| L1 | Explain why background work is restricted and why polling is costly |
| L2 | Schedule work with WorkManager / BGTaskScheduler and receive push notifications |
| L3 | Explain radio states, Doze, standby buckets, push delivery and priorities |
| L4 | Diagnose delayed work, missed notifications and battery complaints |
| L5 | Design background and notification strategies for a product |
| L6 | Operate push at scale: token hygiene, rate limits, delivery monitoring |
How the radio spends energy
- An idle cellular radio takes time and energy to promote to its connected state before the first byte.
- After a transfer it stays in high power for a tail (several seconds, network-configured) before stepping down.
- Wi-Fi is cheaper per byte and has a shorter tail, but the same pattern holds.
Design consequences:
- Batch non-urgent traffic (analytics, logs, prefetches) and send it together, ideally when the radio is already awake for user activity or when on Wi-Fi and charging.
- Coalesce periodic work into the same moments (the model's unaligned schedules cost more than their sum).
- Push instead of poll for changes users care about.
- Prefetch on Wi-Fi/charging for content needed later (tomorrow's menu).
Android background execution
- Doze (device idle) and App Standby buckets (active, working set, frequent, rare, restricted, based on how recently and often the user uses the app) limit jobs, alarms and network access for background apps.
- WorkManager is the API for deferrable, guaranteed work: constraints (unmetered network, charging, battery not low), backoff, chaining, unique work (one sync at a time), and expedited work for short, important tasks.
- Foreground services for user-visible ongoing work, with a notification and a declared type (location, data sync, media…); restricted and reviewed by Google Play.
- Exact alarms need permission and justification; prefer inexact scheduling.
iOS background execution
- Apps are suspended shortly after leaving the foreground. Ways to run in the background:
- BGTaskScheduler:
BGAppRefreshTask(short refreshes) andBGProcessingTask(longer work, optionally requiring power and network), run when the system chooses based on usage patterns; - background URL sessions for uploads and downloads that continue while suspended or terminated;
- background push (content-available) to wake the app briefly; heavily rate-limited;
- specific modes: audio, location updates, VoIP, Bluetooth, each reviewed by Apple.
- There's no general "keep running" option; design for the system to decide.
Push notifications end to end
app ── registers with FCM (Android) / APNs (iOS) ──→ device token
app ── sends token + user ID ──→ TiffinBox server (stores tokens per user/device; refreshes on change)
server event (OrderOutForDelivery) ──→ notification service ──→ FCM / APNs (authenticated) ──→ device ──→ system UI or app code
- Tokens change (reinstall, restore, refresh): update them whenever the app starts; delete tokens the provider reports as unregistered.
- Payloads: title and body for display, plus data (order ID) for the tap's deep link; small (≈ 4 KB limit).
- Priority: high for time-sensitive messages that the user will see (wakes the device in Doze); normal for the rest. Misusing high priority gets deprioritised.
- Collapse keys / thread IDs: "order status" updates replace each other instead of piling up; TTL: an ETA update older than 10 minutes is pointless.
- Channels (Android) and categories (iOS): "Delivery updates", "Offers", "Account": users mute offers without losing delivery alerts.
- Permission: Android 13+ requires
POST_NOTIFICATIONS; iOS requires authorisation (or provisional, quiet delivery). Ask in context ("Get notified when your lunch is on its way?"). - Server side: the notification service consumes events (Volume 19, chapter 211E), deduplicates by event ID, respects quiet hours and preferences, rate-limits, and records delivery outcomes.
Live delivery tracking
- iOS Live Activities (ActivityKit): a lock-screen and Dynamic Island view of the delivery, started when the order goes out, updated by push notifications to the activity (no app process needed), ended on delivery.
- Android: an ongoing notification with progress (Android's progress-centric "Live Updates" style on recent versions), updated by push; a foreground service only if the app itself must actively work (the rider app's location sharing).
- Both have limits on update frequency and duration: send meaningful updates (status changes, ETA changes of more than a couple of minutes), not every GPS point.
Location
- The rider app needs location during deliveries: fused location provider (Android) / Core Location (iOS), with accuracy and interval matched to need (every 5–10 s while moving; nothing when idle), a foreground service or background location mode while on a delivery, and clear disclosure.
- The customer app rarely needs location in the background: approximate location while in use to find nearby kitchens is enough.
- Geofencing lets the OS watch for arrival near a place (the kitchen) cheaply, instead of the app tracking continuously.
Common traps
- Polling in the background for updates.
- Unbatched analytics waking the radio every minute.
- High-priority pushes for marketing.
- Stale tokens never cleaned up.
- Foreground services used to dodge background limits.
Lab: an hour of radio time
Setup. A Python model on the lab machine of a cellular radio, using assumed values typical of published LTE measurements (real values vary by device, network and generation):
| Parameter | Value |
|---|---|
| power while transferring | 1.2 W |
| power in the high-power tail after a transfer | 1.0 W |
| tail length | 10 s |
| promotion (wake-up) time from idle | 0.3 s at transfer power |
| one small request + response | 0.2 s |
| idle power | 0.02 W |
A transfer that starts while the radio is still in its tail extends it (no new promotion). The model sums radio time in high power and energy over one hour for four app behaviours.
Results
| Behaviour | Transfers per hour | Radio in high power | Energy |
|---|---|---|---|
| nothing (idle baseline) | 0 | 0 min | 20 mWh |
| analytics event every 60 s | 60 | 10.5 min | 193 mWh |
| order status polled every 30 s | 120 | 21.0 min | 366 mWh |
| both, unaligned (polls at :00 and :30, events at :15) | 180 | 31.5 min | 539 mWh |
| analytics batched every 15 min; order status by push (4 pushes) | 8 | 1.4 min | 43 mWh |
A phone battery holds roughly 15,000–20,000 mWh (4,000–5,000 mAh at ~3.85 V), so the worst case costs about 3% of the battery per hour from the radio alone, every hour the app is allowed to run in the background.
What it shows
- The tail dominates. Each tiny transfer costs ~0.2 s of actual work and up to 10 s of high-power tail; 120 polls an hour keep the radio awake a third of the time.
- Unaligned schedules add up: two periodic jobs at different offsets cost more than either, because neither's tail is shared.
- Batching plus push cut energy by 12× while delivering the same information (status changes still arrive immediately by push; analytics arrive in batches nobody notices).
- This is why both platforms restrict background work: the OS is protecting the user's battery from exactly these patterns.
Try it yourself
- Align the analytics events with the polls (send them in the same transfer) and recompute.
- Shorten the tail to 5 s (a different network configuration) and see which conclusions change.
- Model a rider app sending location every 5 s for 2 hours of deliveries, then every 30 s; compare energy.
- On an Android device, compare battery usage in the system's battery settings for two builds: polling every 30 s versus FCM push.
Revision sheet: background work, push and battery
Key ideas
- Radio promotion and tail make many small transfers expensive; batch, coalesce, push, prefetch on Wi-Fi/charging.
- Android: Doze, App Standby buckets, WorkManager with constraints, foreground services with types, inexact alarms.
- iOS: suspension; BGTaskScheduler, background URL sessions, rate-limited background push, reviewed modes.
- Push: tokens and refresh, payloads with deep links, priority, collapse keys, TTL, channels/categories, permission in context, server-side dedupe and limits.
- Live tracking: Live Activities (iOS) and ongoing progress notifications (Android), updated by push, with meaningful updates only.
- Location matched to need; approximate in the customer app; foreground service or background mode only for the rider during deliveries; geofences.
Numbers to remember
- Model (assumed LTE values): polling every 30 s ≈ 366 mWh/h; polling + per-minute analytics ≈ 539 mWh/h (~3% battery/h); batching + push ≈ 43 mWh/h.
- Push payloads ≈ 4 KB.
Glossary
- Doze: Android's idle mode restricting background activity.
- App Standby bucket: Android's usage-based priority class for background work.
- FCM / APNs: Firebase Cloud Messaging / Apple Push Notification service.
- Collapse key: replaces earlier undelivered messages of the same kind.
- Live Activity: iOS's live lock-screen and Dynamic Island view of an ongoing event.