
From Foreground Services to WorkManager: How We Cut Battery Drain by 70%
40% of my users on Android 14 were crashing. Every. Single. Day. The crash logs all said the same thing: ForegroundServiceStartNotAllowedException . My auto backup service that had worked fine for four years just... stopped working. Google had finally won the war against background services, and I was collateral damage. The Old Way Worked Great (Until It Didn't) Our All Backup & Restore app (2M+ downloads) had a simple approach since 2020: start a foreground service on boot, listen for app installs, backup immediately. Users loved the "real-time" feel. class BootCompleteReceiver : BroadcastReceiver () { override fun onReceive ( context : Context ?, intent : Intent ?) { if ( intent ?. action == "android.intent.action.BOOT_COMPLETED" ) { context ?. startForegroundService ( serviceIntent ) } } } The service would show a persistent notification, register broadcast receivers for PACKAGE_ADDED and PACKAGE_REPLACED, and backup any new app within seconds. Then the complaints started rolling in
Continue reading on Dev.to
Opens in a new tab


