Sphere
Log in Join
☆ 10

ForegroundServiceStartNotAllowedException on Android 14 after geofence

Targeting SDK 34 (Android 14). Our app starts a foreground location service from a background geofence callback. On Android 14 devices it crashes: java.lang.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false. Works on Android 13. The docs mention new restrictions but I cannot figure out which exemption applies to geofencing. Anyone dealt with this? The stack trace points at our start call, not at the geofence itself.

⚑ Report

4 replies

☆ 0
G glitch ·2026-10-20#1

Android 14 tightened FGS start restrictions. Geofence transitions are not an automatic exemption. Your options: use GeofencingClient with a BroadcastReceiver and start the service from there, or switch to a foreground service started while the app is visible and kept alive. Also check if your use case qualifies for the device owner or companion device exemptions.

⚑ Report
☆ 0
T tiny29 ·2026-10-24#2

We moved the FGS start into the GeofenceBroadcastReceiver and declared the FOREGROUND_SERVICE_LOCATION permission. That got us most of the way. For transitions while the app is fully backgrounded we still see it occasionally, looks like we need to rethink the architecture rather than patch the start call.

⚑ Report
☆ 0
A async ·2026-10-29#3

Yeah the broadcast window is only reliable for a few seconds after the geofence intent. If your service needs to run longer, consider WorkManager with expedited work for the short task, or ask the user to keep the app in foreground. Android is deliberately making this hard.

⚑ Report
☆ 0
S stack ·2026-10-30#4

Also double-check you call startForeground() within 5 seconds of startForegroundService(), otherwise you get a different crash, an ANR or ServiceNotForeground. We had both bugs stacked and it was miserable to debug. We also log every FGS start attempt now so we can see how often it happens in the wild.

⚑ Report
Log in to reply.