react-native-background-geolocation: onLocation method seems to be ignored when the device "wakes up" after no activity time

Your Environment

  • Plugin version: 3.0.54 (354)
  • Platform: Android
  • OS version: Oxygen Os 9.0.11
  • Device manufacturer / model: OnePlus ONEPLUS A5010 @ 9 (react-native)
  • React Native version (react-native -v): react-native-cli: 2.0.1. react-native: 0.62.2
  • Plugin config
{
  "activityRecognitionInterval": 10000,
  "allowIdenticalLocations": false,
  "authorization": {},
  "autoSync": true,
  "autoSyncThreshold": 0,
  "batchSync": false,
  "configUrl": "",
  "debug": true,
  "deferTime": 0,
  "desiredAccuracy": -1,
  "desiredOdometerAccuracy": 100,
  "disableAutoSyncOnCellular": false,
  "disableElasticity": false,
  "disableLocationAuthorizationAlert": false,
  "disableMotionActivityUpdates": false,
  "disableStopDetection": false,
  "distanceFilter": 10,
  "elasticityMultiplier": 1,
  "enableHeadless": false,
  "enableTimestampMeta": false,
  "encrypt": false,
  "extras": {},
  "fastestLocationUpdateInterval": -1,
  "forceReloadOnBoot": false,
  "forceReloadOnGeofence": false,
  "forceReloadOnHeartbeat": false,
  "forceReloadOnLocationChange": false,
  "forceReloadOnMotionChange": false,
  "forceReloadOnSchedule": false,
  "foregroundService": true,
  "geofenceInitialTriggerEntry": true,
  "geofenceModeHighAccuracy": false,
  "geofenceProximityRadius": 1000,
  "geofenceTemplate": "",
  "headers": {},
  "headlessJobService": "com.transistorsoft.rnbackgroundgeolocation.HeadlessTask",
  "heartbeatInterval": -1,
  "httpRootProperty": "location",
  "httpTimeout": 60000,
  "isMoving": false,
  "locationAuthorizationRequest": "Always",
  "locationTemplate": "",
  "locationTimeout": 60,
  "locationUpdateInterval": 1000,
  "locationsOrderDirection": "ASC",
  "logLevel": 5,
  "logMaxDays": 3,
  "maxBatchSize": -1,
  "maxDaysToPersist": 1,
  "maxRecordsToPersist": -1,
  "method": "POST",
  "minimumActivityRecognitionConfidence": 75,
  "motionTriggerDelay": 0,
  "notification": {
    "layout": "",
    "title": "",
    "text": "Location Service activated",
    "color": "",
    "channelName": "TSLocationManager",
    "smallIcon": "",
    "largeIcon": "",
    "priority": 0,
    "strings": {},
    "actions": []
  },
  "params": {},
  "persist": true,
  "persistMode": 2,
  "schedule": [],
  "scheduleUseAlarmManager": false,
  "speedJumpFilter": 300,
  "startOnBoot": true,
  "stationaryRadius": 25,
  "stopAfterElapsedMinutes": 0,
  "stopOnStationary": false,
  "stopOnTerminate": false,
  "stopTimeout": 1,
  "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
  "url": "",
  "useSignificantChangesOnly": false,
  "enabled": true,
  "schedulerEnabled": false,
  "trackingMode": 1,
  "odometer": 0,
  "isFirstBoot": false,
  "didLaunchInBackground": false
}

Expected Behavior

onLocation method seems to be deleted or ignored when the device “wakes up” after a lot of time with no activity

Actual Behavior

Let’s say the device has been “sleeping” (as me) all night long 😉. I wake up, and go out with my dogs. I see in the logs the first thing of today the TSConfig print, and normal activity of the TrackingService: LocationResult, showing all the locations I am during the walk. But the onLocation method defined when I launched the application is lost after “the night time” (better to say the “inactivity time”)

Steps to Reproduce

  1. I have been playing with the standard demo code you have in your github page and define a onLocation method where I do my stuff
  2. When the app is launching it works well, each time the “tracking service” finds a new location, the onLocation method is trigerred and works perfectly
  3. Night time / long inactivity time
  4. The Tracking Service “wakes up” correctly and works correctly, but onLocation is not called at all (I added a “BackgroundGeolocationService.log” to see if it even enters in the method, but it doesn’t).

Context

I need an onLocation method working every time. You can see in the logs below the “last moments” of yesterday, and in “05-09 23:27:56.859” the onLocation method being called with no problems… and the very first moments of today, with more Tracking Service location changes, but onLocation is not called at all anymore.

Debug logs

Logs

╔═════════════════════════════════════════════
║ Motion Transition Result
╠═════════════════════════════════════════════
╟─ 🎾  ENTER: still
╚═════════════════════════════════════════════
05-09 23:27:55.312 INFO [TSLog log] 
05-09 23:27:55.344 INFO [LocationRequestService b] 
  ℹ️  Location availability: true
05-09 23:27:55.548 DEBUG [ActivityRecognitionService onDestroy] 
  🔴  ActivityRecognitionService destroyed
05-09 23:27:55.648 DEBUG [HttpService a] 
╔═════════════════════════════════════════════
║ 📶  Connectivity change: connected? true
╠═════════════════════════════════════════════

05-09 23:27:56.546 DEBUG [HttpService a] 
╔═════════════════════════════════════════════
║ 📶  Connectivity change: connected? false
╠═════════════════════════════════════════════

05-09 23:27:56.822 INFO [LocationRequestService a] 
╔═════════════════════════════════════════════
║ motionchange LocationResult: 1
╠═════════════════════════════════════════════
╟─ 📍  Location[fused XXXXXX, XXXXXX hAcc=17 et=+6d5h16m16s853ms alt=277.20001220703125 vel=0.0 bear=90.0 vAcc=19 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}], age: 1469ms, time: 1589059675350

05-09 23:27:56.829 INFO [TSLocationManager onSingleLocationResult] 
  🔵  Acquired motionchange position, isMoving: false
05-09 23:27:56.830 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 16.871
05-09 23:27:56.834 DEBUG [LocationRequestService onDestroy] 

05-09 23:27:56.859 INFO [TSLog log] 
  ℹ️  🚀 IT ENTERS IN THE ONLOCATION METHOD !!!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ***********************************
05-09 23:27:56.859 INFO [TSLog log] 
  ℹ️  🚀 DO MY STUFF ... 

05-09 23:27:56.881 DEBUG [LocationRequestService a] SingleLocationRequest 1 isFinished? true
05-09 23:27:56.881 INFO [ActivityRecognitionService a] 
  🎾  Start motion-activity updates
05-09 23:27:56.881 INFO [TSLog log] 
  🎾  Start monitoring stationary region (radius: 150.0m XXXXXXXX, XXXXXXXXXX hAcc=16.871)
05-09 23:27:56.884 INFO [TSLog log] 
  ✅  INSERT: 6a07c08a-b9ee-4559-a86a-95b7c36030eb
05-09 23:27:56.885 INFO [TSLog log] 
╔═════════════════════════════════════════════
║ TrackingService motionchange: false
╠═════════════════════════════════════════════

05-09 23:27:56.983 DEBUG [ActivityRecognitionService a] 
  🚘 ️DetectedActivity [type=STILL, confidence=100]
05-09 23:27:57.019 DEBUG [ActivityRecognitionService a] 
  🚘 ️DetectedActivity [type=STILL, confidence=100]
05-09 23:27:57.052 INFO [ActivityRecognitionService a] 
╔═════════════════════════════════════════════
║ Motion Transition Result
╠═════════════════════════════════════════════
╟─ 🎾  ENTER: still
╚═════════════════════════════════════════════
05-09 23:27:57.060 INFO [TSLog log] 
╔═════════════════════════════════════════════
║ Motion Transition Result
╠═════════════════════════════════════════════
╟─ 🎾  ENTER: still
╚═════════════════════════════════════════════
05-09 23:27:57.075 INFO [TSLog log] 
05-09 23:27:57.165 DEBUG [TrackingService onDestroy] 
  🔴  TrackingService destroyed
05-09 23:27:57.325 DEBUG [ActivityRecognitionService onDestroy] 
  🔴  ActivityRecognitionService destroyed
05-09 23:28:01.300 INFO [TSScheduleManager oneShot] 
  ⏰ Oneshot TERMINATE_EVENT is already pending
05-09 23:28:05.117 INFO [ScheduleEvent onOneShot] 
╔═════════════════════════════════════════════
║ ⏰ OneShot event fired: TERMINATE_EVENT
╠═════════════════════════════════════════════

05-09 23:28:05.122 DEBUG [TerminateEvent <init>] 
  ℹ️  TERMINATE_EVENT ignored (MainActivity is still active).
05-09 23:33:41.111 INFO [TSScheduleManager oneShot] 
  ⏰ Scheduled OneShot: TERMINATE_EVENT in 10000ms (jobID: -1708771588)
05-09 23:33:51.149 INFO [ScheduleEvent onOneShot] 
╔═════════════════════════════════════════════
║ ⏰ OneShot event fired: TERMINATE_EVENT
╠═════════════════════════════════════════════

05-09 23:33:51.155 DEBUG [TerminateEvent <init>] 
  ℹ️  TERMINATE_EVENT ignored (MainActivity is still active).
05-09 23:38:01.509 DEBUG [HttpService a] 
╔═════════════════════════════════════════════
║ 📶  Connectivity change: connected? false
╠═════════════════════════════════════════════

05-09 23:38:02.013 DEBUG [HttpService a] 
╔═════════════════════════════════════════════
║ 📶  Connectivity change: connected? true
╠═════════════════════════════════════════════

05-10 08:36:23.246 INFO [TSConfig print] 
╔═════════════════════════════════════════════
║ TSLocationManager version: 3.0.54 (354)
╠═════════════════════════════════════════════
╟─ OnePlus ONEPLUS A5010 @ 9 (react-native)
{
  "activityRecognitionInterval": 10000,
  "allowIdenticalLocations": false,
  "authorization": {},
  "autoSync": true,
  "autoSyncThreshold": 0,
  "batchSync": false,
  "configUrl": "",
  "debug": true,
  "deferTime": 0,
  "desiredAccuracy": -1,
  "desiredOdometerAccuracy": 100,
  "disableAutoSyncOnCellular": false,
  "disableElasticity": false,
  "disableLocationAuthorizationAlert": false,
  "disableMotionActivityUpdates": false,
  "disableStopDetection": false,
  "distanceFilter": 10,
  "elasticityMultiplier": 1,
  "enableHeadless": false,
  "enableTimestampMeta": false,
  "encrypt": false,
  "extras": {},
  "fastestLocationUpdateInterval": -1,
  "forceReloadOnBoot": false,
  "forceReloadOnGeofence": false,
  "forceReloadOnHeartbeat": false,
  "forceReloadOnLocationChange": false,
  "forceReloadOnMotionChange": false,
  "forceReloadOnSchedule": false,
  "foregroundService": true,
  "geofenceInitialTriggerEntry": true,
  "geofenceModeHighAccuracy": false,
  "geofenceProximityRadius": 1000,
  "geofenceTemplate": "",
  "headers": {},
  "headlessJobService": "com.transistorsoft.rnbackgroundgeolocation.HeadlessTask",
  "heartbeatInterval": -1,
  "httpRootProperty": "location",
  "httpTimeout": 60000,
  "isMoving": false,
  "locationAuthorizationRequest": "Always",
  "locationTemplate": "",
  "locationTimeout": 60,
  "locationUpdateInterval": 1000,
  "locationsOrderDirection": "ASC",
  "logLevel": 5,
  "logMaxDays": 3,
  "maxBatchSize": -1,
  "maxDaysToPersist": 1,
  "maxRecordsToPersist": -1,
  "method": "POST",
  "minimumActivityRecognitionConfidence": 75,
  "motionTriggerDelay": 0,
  "notification": {
    "layout": "",
    "title": "",
    "text": "Location Service activated",
    "color": "",
    "channelName": "TSLocationManager",
    "smallIcon": "",
    "largeIcon": "",
    "priority": 0,
    "strings": {},
    "actions": []
  },
  "params": {},
  "persist": true,
  "persistMode": 2,
  "schedule": [],
  "scheduleUseAlarmManager": false,
  "speedJumpFilter": 300,
  "startOnBoot": true,
  "stationaryRadius": 25,
  "stopAfterElapsedMinutes": 0,
  "stopOnStationary": false,
  "stopOnTerminate": false,
  "stopTimeout": 1,
  "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
  "url": "",
  "useSignificantChangesOnly": false,
  "enabled": true,
  "schedulerEnabled": false,
  "trackingMode": 1,
  "odometer": 0,
  "isFirstBoot": false,
  "didLaunchInBackground": false
}
05-10 08:36:23.250 INFO [TSConfig print] 
╔═════════════════════════════════════════════
║ DEVICE SENSORS
╠═════════════════════════════════════════════
╟─ ✅  ACCELEROMETER: {Sensor name="BMI160 Accelerometer", vendor="BOSCH", version=2062600, type=1, maxRange=39.22661, resolution=0.0023956299, power=0.18, minDelay=2500}
╟─ ✅  GYROSCOPE: {Sensor name="BMI160 Gyroscope", vendor="BOSCH", version=2062600, type=4, maxRange=34.906586, resolution=0.0010681152, power=0.9, minDelay=2500}
╟─ ✅  MAGNETOMETER: {Sensor name="AK09911 Magnetometer", vendor="AKM", version=1, type=2, maxRange=4911.9995, resolution=0.5996704, power=2.4, minDelay=20000}
╟─ ✅  SIGNIFICANT_MOTION: {Sensor name="Significant Motion Detector", vendor="QTI", version=2, type=17, maxRange=1.0, resolution=1.0, power=0.17999268, minDelay=-1}
╚═════════════════════════════════════════════
05-10 08:36:23.264 INFO [BackgroundGeolocation <init>] 
  ✅  Google Play Services: connected (version code:12451000)
05-10 08:36:23.281 DEBUG [TSConfig c] ℹ️   Persist config, dirty: [isMoving]
05-10 08:36:23.284 DEBUG [TSLocationManager$4 run] 
  ℹ️  Load last odometer location: Location[TSLocationManager XXXXXXXX,XXXXXXXXX hAcc=17 t=?!? et=?!? vAcc=??? sAcc=??? bAcc=??? {Bundle[{odometer=0.0}]}]
05-10 08:36:23.293 INFO [HeartbeatService a] 
  🔴  Stop heartbeat
05-10 08:36:23.295 DEBUG [TSGeofenceManager stopMonitoringStationaryRegion] 
  🔴  Stop monitoring stationary region
05-10 08:36:23.317 DEBUG [b b] 
  ℹ️  LocationAuthorization: Permission granted
05-10 08:36:23.319 INFO [TrackingService a] 
  🔵  setPace: false → true
05-10 08:36:23.320 INFO [ActivityRecognitionService a] 
╔═════════════════════════════════════════════
║ Motion Transition Result
╠═════════════════════════════════════════════
╟─ 🔴  EXIT: still
╟─ 🎾  ENTER: walking
╚═════════════════════════════════════════════
05-10 08:36:23.344 DEBUG [HttpService startMonitoringConnectivityChanges] 
  🎾  Start monitoring connectivity changes
05-10 08:36:23.350 INFO [BackgroundGeolocation e] 
  🎾  Start monitoring location-provider changes
05-10 08:36:23.354 DEBUG [b prune] 
  ℹ️  PRUNE -1 days
05-10 08:36:23.377 DEBUG [HttpService a] 
╔═════════════════════════════════════════════
║ 📶  Connectivity change: connected? true
╠═════════════════════════════════════════════

05-10 08:36:23.669 INFO [TrackingService h] 
╔═════════════════════════════════════════════
║ TrackingService motionchange: true
╠═════════════════════════════════════════════

05-10 08:36:23.670 DEBUG [ActivityRecognitionService onDestroy] 
  🔴  ActivityRecognitionService destroyed
05-10 08:36:23.796 INFO [LocationRequestService b] 
  ℹ️  Location availability: true
05-10 08:36:24.207 INFO [LocationRequestService a] 
╔═════════════════════════════════════════════
║ motionchange LocationResult: 1
╠═════════════════════════════════════════════
╟─ 📍  Location[fused XXXXXXXX,XXXXXXXXX hAcc=15 et=+6d14h24m43s667ms alt=276.1000061035156 vAcc=12 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}], age: 2039ms, time: 1589092582165

05-10 08:36:24.208 INFO [TSGeofenceManager start] 
  🎾  Start monitoring geofences
05-10 08:36:24.228 INFO [TSLocationManager onSingleLocationResult] 
  🔵  Acquired motionchange position, isMoving: true
05-10 08:36:24.229 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 14.889
05-10 08:36:24.274 DEBUG [LocationRequestService onDestroy] 
05-10 08:36:24.302 INFO [TSLocationManager requestLocationUpdates] 
  🎾  Location-services: ON
05-10 08:36:24.305 INFO [TSLocationManager requestLocationUpdates] 
  🎾  Location-services: ON
05-10 08:36:24.306 DEBUG [TSConfig translateDesiredAccuracy] translateDesiredAccuracy (true): -1
05-10 08:36:24.309 DEBUG [LocationRequestService a] SingleLocationRequest 1 isFinished? true
05-10 08:36:24.310 INFO [ActivityRecognitionService a] 
  🎾  Start motion-activity updates
05-10 08:36:24.314 INFO [TSLocationManager removeLocationUpdates] 
  🔴  Location-services: OFF
05-10 08:36:24.314 INFO [b persist] 
  ✅  INSERT: 4d3e0b18-a26b-4760-bb5e-775d0ae84dce
05-10 08:36:24.320 INFO [TSLocationManager requestLocationUpdates] 
  🎾  Location-services: ON
05-10 08:36:24.322 DEBUG [TSConfig translateDesiredAccuracy] translateDesiredAccuracy (true): -1
05-10 08:36:24.461 INFO [TrackingService b] 
  ℹ️  Location availability: true
05-10 08:36:24.857 DEBUG [TrackingService a] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused XXXXXXXX,XXXXXXXXX hAcc=20 et=+6d14h24m45s280ms alt=276.1000061035156 vel=0.016776463 bear=283.21585 vAcc=20 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}], age: 1074ms, time: 1589092583777

...
...
and so on

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 27 (11 by maintainers)

Most upvoted comments

The OS has terminated your app in the background to free up memory, which is a normal thing to occur.

Your app no longer exists at all. Your Android app is “Headless

See wiki Headless JS.

“Connectivity change: connected? true” says that the app was relaunched?

No, that’s the last log-entry where your Android MainActivity (where your RN app lives) was alive. At some point after that, Android terminated it.

The plugin has registered services that are capable of responding to events headless (eg Motion API)

Ok, thank you very much again !!! For sure, we will buy the license as soon as we finish the debugging stuff 😉