Why a foreground service

GPS doesn't run for free in the background

Module 11's LiveViewModel reads GPS fixes while LiveScreen is on screen β€” but a real walk lasts 30 minutes, and the walker's phone spends most of that time in their pocket, screen off, some other app up front. Android is aggressive about killing background work to save battery: background execution limits throttle what a plain background coroutine can do, and Doze mode suspends network and CPU access almost entirely once the screen's been off a while.

There's exactly one sanctioned way around both: a foreground service. It's a Service the system treats as user-visible and important β€” in exchange, it must show a persistent notification the whole time it runs, so the user always knows something is actively using their phone. That trade (a notification you can't dismiss, for GPS that keeps working) is the deal every fitness-tracking, navigation, and delivery app on the Play Store makes.