react-native-background-geolocation: Location event in Android 9 not triggering

The “location” event does not trigger on Android when the app is in background after a few minutes/seconds using DISTANCE_FILTER_PROVIDER. When the app returns to foreground it seems to start triggering again (kind of looks like releasing the queue of pending event triggers)

Your Environment

  • Plugin version: 0.5.3
  • Platform: Android
  • OS version: 9
  • Device manufacturer and model: OnePlus 6 and Motorola Moto G6+
  • Running in Simulator: No
  • React Native version: 0.59.10
  • Plugin configuration options:
{
    locationProvider: BackgroundGeolocation.DISTANCE_FILTER_PROVIDER,
    desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
    stationaryRadius: 20, // in meters
    distanceFilter: 20, // in meters
    debug: false,
    stopOnTerminate: false,
    maxLocations: 5000,
    url: null, // no automatic push
    // Android
    startOnBoot: true,
    interval: 1 * 60 * 1000, // 1 minute
    fastestInterval: 1 * 60 * 1000, // 1 minute
    activitiesInterval: 3 * 60 * 1000, // 3 minutes
    stopOnStillActivity: false,
    startForeground: false,
    notificationsEnabled: false,
    // iOS
    pauseLocationUpdates: false,
}

Context

We have an app that needs to track the user/device movements even in background. It is working perfectly on iOS and tracking locations with interval of seconds (not ideal, but still working well). However in Android only detects location when the app is open in foreground. After placed in background it stops detecting. In other words, the events don’t fire. Additionally, when the app returns to foreground it seems the background location events start firing (like they were on a queue or similar).

Expected Behavior

The app should keep receiving “location” events even if it’s in background.

Actual Behavior

The app only receives in foreground and after background stops. Sometimes a few minutes or seconds after going to background and that’s it.

Possible Fix

No idea. We’re trying with ACTIVITY_PROVIDER to see if it improves.

Debug logs

No logs in background, but they should have appeared. We looked at them with adb logcat and even locally installed apps for that purpose. Once in BG, no more activity.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (14 by maintainers)

Most upvoted comments

I’m pretty much aware of “workaround” in the articles you have posted. But your problem is startForeground: false. When you set it to true, it should fix your problem.