Dev.to
7/21/2026

Keeping Android Background Services Alive in a World of OEM Battery Optimizations
Short summary
A developer shares lessons from building Muffle, an Android app that automates phone silencing based on calendar and location triggers. The core challenge is keeping background services alive despite aggressive OEM battery optimizations from Samsung, Xiaomi, and OnePlus that kill non-UI processes. The solution uses a persistent Foreground Service with START_STICKY, a BroadcastReceiver for system state changes, and careful handling of AudioManager and Do Not Disturb permissions.
- •OEM battery optimizations from Samsung, Xiaomi, and OnePlus aggressively kill background services
- •Solution: persistent Foreground Service with visible notification plus START_STICKY and BroadcastReceiver
- •GPS geofencing can fail when OEMs freeze location providers after screen-off; workarounds require device-specific handling
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



