react-native-background-geolocation: BackgroundGeolocation.onGeofence is not working on Android in Killed State

Your Environment

  • Plugin version:4.16.5
  • Platform: Android
  • OS version: 13
  • Device manufacturer / model: Samsung S22 plus
  • React Native version (react-native -v):0.70.6
  • Plugin config BackgroundGeolocation.ready({ debug: false, locationAuthorizationRequest: ‘Always’, showsBackgroundLocationIndicator: false, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, desiredAccuracy: desiredAccuracy ? desiredAccuracy : BackgroundGeolocation.DESIRED_ACCURACY_HIGH, deferTime: 0, startOnBoot: true, enableHeadless: true, preventSuspend: false, stopOnTerminate: false, elasticityMultiplier: 1, foregroundService: true, disableElasticity: false, enableTimestampMeta: false, disableStopDetection: false, geofenceModeHighAccuracy: true, useSignificantChangesOnly: false, disableAutoSyncOnCellular: false, disableMotionActivityUpdates: false, distanceFilter: distanceFilter ?? 9, disableLocationAuthorizationAlert: false, activityType: BackgroundGeolocation.ACTIVITY_TYPE_OTHER, locationAuthorizationAlert: { titleWhenNotEnabled: t(‘title_when_not_enabled’), titleWhenOff: t(‘title_when_off’), instructions: t(‘location_auth_alert_instructions’), cancelButton: t(‘location_auth_alert_cancel’), settingsButton: t(‘location_auth_alert_settings’), }, stopTimeout: 5, desiredOdometerAccuracy: 10, backgroundPermissionRationale: { title: ‘Allow “App” to use your location?’, message: ‘Please select “Change to Always Allow” below so “App” can access your location even when you are not using the app.’, positiveAction: ‘Change to “Always Allow”’, negativeAction: ‘Cancel’, }, })

Expected Behavior

BackgroundGeolocation.onGeofence should work on Android in Killed State

Actual Behavior

BackgroundGeolocation.onGeofence is not working on Android in Killed State

Steps to Reproduce

1.Add Above-mentioned Config for Android Device 2. Move Android Device to killed State 3.geofence event will not trigger for Android in killed State

Debug logs

{ “activityRecognitionInterval”: 10000, “allowIdenticalLocations”: false, “authorization”: {}, “autoSync”: true, “autoSyncThreshold”: 0, “backgroundPermissionRationale”: { “title”: “Allow "App" to use your location?”, “message”: “Please select "Change to Always Allow" below so App can access your location even when you are not using the app.”, “positiveAction”: “Change to "Always Allow"”, “negativeAction”: “Cancel” }, “batchSync”: false, “configUrl”: “”, “crashDetector”: { “enabled”: false, “accelerometerThresholdHigh”: 20, “accelerometerThresholdLow”: 4.5, “gyroscopeThresholdHigh”: 20, “gyroscopeThresholdLow”: 4.5 }, “debug”: false, “deferTime”: 0, “desiredAccuracy”: -1, “desiredOdometerAccuracy”: 10, “disableAutoSyncOnCellular”: false, “disableElasticity”: false, “disableLocationAuthorizationAlert”: false, “disableMotionActivityUpdates”: false, “disableProviderChangeRecord”: false, “disableStopDetection”: false, “distanceFilter”: 9, “elasticityMultiplier”: 1, “enableHeadless”: true, “enableTimestampMeta”: false, “extras”: {}, “fastestLocationUpdateInterval”: -1, “foregroundService”: true, “geofenceInitialTriggerEntry”: true, “geofenceModeHighAccuracy”: true, “geofenceProximityRadius”: 1000, “geofenceTemplate”: “”, “headers”: {}, “headlessJobService”: “com.transistorsoft.rnbackgroundgeolocation.HeadlessTask”, “heartbeatInterval”: -1, “httpRootProperty”: “location”, “httpTimeout”: 60000, “isMoving”: true, “locationAuthorizationRequest”: “Always”, “locationTemplate”: “”, “locationTimeout”: 60, “locationUpdateInterval”: 1000, “locationsOrderDirection”: “ASC”, “logLevel”: 5, “logMaxDays”: 3, “maxBatchSize”: -1, “maxDaysToPersist”: 1, “maxMonitoredGeofences”: 97, “maxRecordsToPersist”: -1, “method”: “POST”, “minimumActivityRecognitionConfidence”: 75, “motionTriggerDelay”: 0, “notification”: { “layout”: “”, “title”: “”, “text”: “Location Service activated”, “color”: “”, “channelName”: “TSLocationManager”, “channelId”: “”, “smallIcon”: “”, “largeIcon”: “”, “priority”: -1, “sticky”: false, “strings”: {}, “actions”: [] }, “params”: {}, “persist”: true, “persistMode”: 2, “schedule”: [], “scheduleUseAlarmManager”: false, “speedJumpFilter”: 300, “startOnBoot”: true, “stationaryRadius”: 25, “stopAfterElapsedMinutes”: 0, “stopOnStationary”: false, “stopOnTerminate”: false, “stopTimeout”: 5, “triggerActivities”: “in_vehicle, on_bicycle, on_foot, running, walking”, “url”: “”, “useSignificantChangesOnly”: false, “enabled”: true, “schedulerEnabled”: false, “trackingMode”: 1, “odometer”: 4757.9638671875, “isFirstBoot”: true, “didLaunchInBackground”: false, “didDeviceReboot”: false }

Logs [background-geolocation (20).log](https://github.com/user-attachments/files/17231194/background-geolocation.20.log)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 33 (15 by maintainers)

Most upvoted comments

What is this?? Delete it. It does not belong in index.js:

let getCurrentPosition = () => {
  return new Promise((resolve) => {
    BackgroundGeolocation.getCurrentPosition(
      {
        samples: 1,
        persist: false
      },
      (location) => {
        resolve(location);
      }, (error) => {
        resolve(error);
      });
  });

  
};
let getgeofence= () => {
  return new Promise((resolve) => {
    BackgroundGeolocation.onGeofence((geofence) => {
      resolve(geofence);
      console.log('Geofence event:', geofence);
    });
  });