Designing location tracking

Mobile system design Senior Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Pick the fix

A run tracker requests ACCESS_BACKGROUND_LOCATION at first launch and Play review rejects it. Better approach?

Options
Hint 1 of 1

Does a foreground service count as in use?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Track from a user-started foreground service of type location with while-in-use permission

Correct. No background permission is needed for this flow.

Why not the others?
  • B Ask again with a longer explanation. Play still requires a strong need.
  • C Use a periodic WorkManager job. Too infrequent for a route.
  • D Use exact alarms every second. Wrong tool and drains battery.

30-second answer

Start a foreground service with the location type and a visible notification when the user taps Start. Request location from the Fused Location Provider with a suitable interval and priority. Write points to Room in batches so a crash loses little. Ask for fine location while in use; background location is a separate, harder permission you usually don't need, because the foreground service counts as in use.

Practise saying it · 35 s. No recording, just a timer

Design location tracking.

Say your answer out loud, then check which of these points you covered:

  • Foreground service type location
  • Fused Location Provider
  • Batch to Room
  • While-in-use permission
  • Battery trade-offs

Deep dive

Android 14 requires a declared foreground service type and matching permission.

Balance accuracy and battery with priority and interval; batch updates with maxUpdateDelay.

Stop updates as soon as the run ends.

Users can grant approximate only; handle it.

Common mistakes

  • Requesting background location for a feature that starts in the foreground.
  • Writing every point in its own transaction.
  • Not stopping updates.

Senior take & follow-ups

Foreground service, fused provider, storage, permissions, battery.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why not background location permission?

    Show hint

    A user-started foreground service already counts as in use.

  2. How do you save battery?

    Show hint

    Balanced priority, longer intervals and batched delivery.

Similar on iOS: Getting the user's location iOS uses background location modes rather than a foreground service.

Suggest a fix if something here is wrong or out of date.