Users notice two things immediately: an app that's slow, and an app that kills their battery. The second one gets you uninstalled.
When we built TrackMatee — a continuous GPS trip detection platform — battery life was our most critical constraint. The app had to run in the background for hours, tracking movement across 50+ cities, while barely touching the battery. Here's what we learned.
The Three Main Battery Killers
In any mobile app, battery drain comes from three main sources:
- GPS / Location services — the biggest offender by far
- Network requests — especially frequent polling
- Wake locks — keeping the CPU alive when it should sleep
A naive GPS implementation — polling every second, always-on — can drain a modern phone in under 4 hours. For a platform processing 50,000+ trips daily, that's a non-starter.
Adaptive Sampling: The Fix
The core insight is simple: you don't need the same GPS precision when someone is sitting still as when they're moving at 80 km/h.
We built an adaptive sampler that adjusts polling frequency based on detected movement:
- Speed > 20 km/h → sample every 3 seconds
- Speed 5–20 km/h → sample every 10 seconds
- Speed < 5 km/h → sample every 30 seconds
- Stationary for 2+ minutes → pause GPS, switch to activity detection
The activity detection part is key. Instead of keeping GPS alive during stops, we used the device's accelerometer (via Android's Activity Recognition API) to detect when movement resumed — then re-enabled GPS. The accelerometer uses a fraction of the battery that GPS does.
Batched Writes, Not Constant Writes
Every database write wakes the CPU slightly. Constant small writes — one per GPS event — add up. We batched location events into groups of 10–20 and wrote them in a single SQLite transaction. Same data, a fraction of the CPU cost.
Network syncs followed the same principle: rather than uploading each event immediately, we queued them locally and flushed in batches when on Wi-Fi or strong signal. This also eliminated the constant radio wake-ups that kill battery on cellular.
The Result
Combining adaptive sampling, accelerometer-based pause/resume, batched SQLite writes, and opportunistic network sync, we reduced battery consumption by 35% compared to our initial always-on implementation — with no loss in trip detection accuracy.
The best performance optimisation is the work you don't do. Don't poll GPS when the user is sitting still.
These patterns apply beyond GPS. Any app that runs background services — delivery tracking, health monitoring, location sharing — can apply the same principle: do less work when less precision is needed, and batch everything you can.