react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Reassigning BackgroundGeolocation.onHeartbeat does not remove the previous callback
Your Environment
- Plugin version: 3.4.2
- Platform: Android
- OS version: 9
- Device manufacturer / model: Google Pixel 3
- React Native version (
react-native -v): 0.61.5 - Plugin config
BackgroundGeolocation.ready({
stopOnTerminate: false,
startOnBoot: true,
forceReloadOnBoot:true,
foregroundService:true,
preventSuspend:true,
allowIdenticalLocations:true,
url: 'https://flespi.io/mqtt/messages',
locationTemplate: `{"payload":'{"user.id":"${userId}", "timestamp":"<%= timestamp %>","position.latitude":<%= latitude %>,"position.longitude":<%= longitude %>,"position.speed": <%= speed %>,"position.altitude": <%= altitude %>,"position.direction": <%= heading %>,"position.accuracy": <%= accuracy %>,"activity":"<%= activity.type %>","odometer":<%= odometer %>,"battery":<%= battery.level %>,"event":"<%= event %>"}'}`,
geofenceTemplate: `{"payload":'{"geofence.identifier":"<%= geofence.identifier %>","geofence.action": "<%= geofence.action %>", "user.id":"${userId}", "timestamp": "<%= timestamp %>","position.latitude":<%= latitude %>,"position.longitude":<%= longitude %>,"position.speed": <%= speed %>,"position.altitude": <%= altitude %>,"position.direction": <%= heading %>,"position.accuracy": <%= accuracy %>,"activity":"<%= activity.type %>","odometer":<%= odometer %>,"battery":<%= battery.level %>,"event":"<%= event %>"}'}`,
httpRootProperty:'.',
elasticityMultiplier:2,
heartbeatInterval:60,
schedule: h2h.schedules.length ? h2h.schedules[0].spans : [],
scheduleUseAlarmManager: true,
}
Expected Behavior
I expect the heartbeat callback to change when BackgroundGeolocation.onHeartbeat() is called with a different callback arg.
Actual Behavior
The previous callback continues to be called.
The plugin allows multiple listeners on any particular event. Calling onHeartbeat adds another listener to the stack. It doesn't remove any previous listeners.
See API docs removeListener