We have all been there: you walk into a meeting or a quiet space, expecting your phone to silence itself, only to realize the GPS trigger failed because the system put your app to sleep. As I built Muffle, an Android utility for automated sound profiles, I quickly realized that standard background location polling is insufficient for the modern Android ecosystem.
The Problem: Doze Mode vs. Real-time Needs
Android’s Doze Mode is essential for battery health, but it is the enemy of background tasks that rely on precise location updates. If your app attempts to poll GPS while the device is stationary and the screen is off, the system will batch those requests or kill them entirely. I initially tried using a simple Foreground Service with a LocationListener, but I found that on certain OEMs, even that was getting throttled to save power.
The Solution: Combining FusedLocationProvider with WorkManager
To solve this without draining the user's battery, I shifted my architecture. Instead of a constant location stream, I utilized the FusedLocationProviderClient with a GeofencingClient. By defining physical geofences around high-priority areas (like a workplace or a place of worship), I offload the heavy lifting to the Google Play Services location hardware.
kotlin
val geofenceRequest = GeofencingRequest.Builder().apply {
addGeofences(geofenceList)
setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
}.build()
When a geofence is triggered, the OS sends a PendingIntent to a BroadcastReceiver. Because geofencing events are handled by the system, this bypasses the standard Doze Mode restrictions on polling. If the geofence event requires a more complex calculation (like checking a calendar event or prayer time), I hand the logic off to WorkManager with ExistingPeriodicWorkPolicy.KEEP to ensure the task eventually executes even if the device was in a deep sleep state.
A Necessary Tradeoff
The tradeoff here is responsiveness. Geofencing relies on the system's approximation of your location, which can sometimes lag by a few hundred meters or a few seconds depending on whether the phone has a clear view of the sky. I opted for this over a high-frequency polling service because it respects the user's battery—a non-negotiable for a utility app.
Building Muffle has taught me that on Android, the best background architecture isn't the one that fights the OS for resources, but the one that uses the platform's native hooks to work in harmony with power-saving states. By leveraging the system's own geofencing engine, I managed to create a reliable silent-mode trigger that doesn't sacrifice the user's battery life.

























