Skip to content

Foreground service not stopping when app is closed or swiped away #7

@ukadmin

Description

@ukadmin

When using background_location_2 on Android, the foreground service (BackgroundLocationService) continues running even after the app is closed or removed from the "Recents" / Task Manager.

I already added android:stopWithTask="true" to the entry in AndroidManifest.xml (inside ).

I also tried calling BackgroundLocation.stopLocationService() in Flutter (dispose, detached, onWillPop).

The method gets called, but if the app is swiped away, Flutter is already detached and I see a NullPointerException in the logs. The notification stays visible and the service keeps running.

Logs

I/flutter: 🛑 GPS-Service über detached gestoppt
E/MethodChannel#com.almoullim.background_location/methods: java.lang.NullPointerException
at com.almoullim.background_location.BackgroundLocationService.stopLocationService(BackgroundLocationService.kt:149)
...
W/FlutterJNI: Tried to send a platform message response, but FlutterJNI was detached

Expected behavior
The foreground service should automatically stop when the app is closed or swiped away (like other location plugins).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions