Delivery riders using our Flutter app reported that live location tracking stopped updating after about 5 minutes with the app in background. Dispatch could no longer see rider positions. The issue spiked after users upgraded to Android 12 and 13.
- Flutter with android foreground service via flutter_foreground_task
- geolocator for position stream
- Android 12–14, targetSdk 33 at time of bug
Android 12 requires declaring foregroundServiceType in AndroidManifest.xml. We had a foreground notification but no location type declaration. Android killed the service silently when the app went to background because the system treated it as an invalid foreground service.
AndroidManifest.xml:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<service
android:name=".LocationForegroundService"
android:foregroundServiceType="location"
android:exported="false" />
Flutter side — request background location only after foreground is granted, and start the service with explicit type on Android 14:
await FlutterForegroundTask.startService(
notificationTitle: 'Tracking delivery',
notificationText: 'Location active',
callback: _locationCallback,
);
// Android 14+: verify service is running after resume
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
_ensureTrackingServiceAlive();
}
}
- Audit manifest foregroundServiceType for every background feature
- Test background location for 30+ minutes on Android 12+ physical devices
- Log service start/stop events to Crashlytics breadcrumbs
- Show riders a clear persistent notification — required and builds trust
Location update gaps dropped from 23% of shifts to under 2%. Dispatch SLA for rider visibility went back to 99.5%.