Background Service Not Working

Actions & Logic

I'm building an app to track a marketing employee's location, route, and distance from the time they punch in until they punch out. This requires the app to continue tracking in the background, even when it is closed.

The Problem

My app's background service is not running persistently on Android, even after following the official documentation and best practices. The service is started, but it stops working when the app is minimized. The database is not updated periodically.

What have you tried so far?

What I've Done

  • Permissions: I have added all necessary custom permissions, including ACCESS_BACKGROUND_LOCATION, FOREGROUND_SERVICE, SCHEDULE_EXACT_ALARM, and RECEIVE_BOOT_COMPLETED.

  • Dependencies: I am using the correct versions of flutter_background_service, flutter_local_notifications, and geolocator as required by the custom code.

  • Android Manifest: I have manually edited the AndroidManifest.xml to include the <service> tag with tools:replace="android:exported". All other tags are correctly nested within <application>.

  • Device Settings: I have confirmed that the app has all permissions and that battery optimization is set to "Unrestricted" and "Auto-Launch" is enabled.

  • Testing: I have tested with a simplified Ctime function that writes a timestamp to the database, but it also fails when the app is closed.

Did you check FlutterFlow's Documentation for this topic?
Yes
3
1 reply