Closed raghavdnn closed 3 years ago
I think the code below is weird.
BackgroundGeolocation.checkStatus(({ isRunning }) => {
if (isRunning) {
BackgroundGeolocation.start(); // service was running -> rebind all listeners
}
});
BackgroundGeolocation.start()
doesn't bind anything.
You don't have to restart it.
@darron1217 But if I don't do this:
BackgroundGeolocation.checkStatus(({ isRunning }) => {
if (isRunning) {
BackgroundGeolocation.start(); // service was running -> rebind all listeners
}
});
then location doesn't log in the console after closing and reopening the app again. Also If I define a headless task to get locations even if the app is killed, the next time I open the app while service is running, it throws an error:
registerHeadlessTask or registerCancellableHeadlessTask called multiple times for same key 'com.marianhello.bgloc.react.headless.Task'
I've tried commenting the headless task, I thought that was preventing locations to show up in console after closing and re-opening the app but the same thing happened. Location does not show up in console after re-opening the app.
@raghav-ado I found bug on Android targetSdk 29+ and fixed it.
Please update your plugin version to 0.6.6
@darron1217 still same error registerHeadlessTask or registerCancellableHeadlessTask called multiple times for same key 'com.marianhello.bgloc.react.headless.Task
after upgrading to version 0.6.6
@raghav-ado I guess your code allows calling start()
multiple times.
You should run start()
only if status is not running
@raghav-ado did you solved it?
@darron1217 Even after starting service only when it's not running, whenever I close the app, wait for headless task to log location and open the app again, I still get registerHeadlessTask or registerCancellableHeadlessTask called multiple times for same key 'com.marianhello.bgloc.react.headless.Task'
and location updates stop even when app is open after this error. Maybe service is being stopped after encoutering this error.
@raghav-ado Thanks for your feedback. I'll check this issue if available.
Same problem here
@walterdl I kind of got it to work. I have moved my headless task inside BackgroundGeolocation.on('start', ...)
then everything works as expected.
BackgroundGeolocation.on('start', async () => {
console.log('[INFO] BackgroundGeolocation service has been started');
// headless task
BackgroundGeolocation.headlessTask(async (event) => {
// your task
}
});
});
I think that way your headless task only gets registered once and doesn't cause 'multiple times for same key'
error.
It stops on BackgroundGeolocation.stop()
as well.
I've used
BackgroundGeolocation.headlessTask()
to get location updates even if the app is killed, which works fine but as soon as I stop the tracking usingBackgroundGeolocation.stop()
everything stops but as soon as I close the app, the headless task again starts keep on sending locations even without executingBackgrounGeolocation.start()
first.Your Environment
BackgroundGeolocation.on('location', (location) => { // handle your locations here // to perform long running operation on iOS // you need to create background task BackgroundGeolocation.startTask((taskKey) => { // execute long running task // eg. ajax post location // IMPORTANT: task has to be ended by endTask console.log('ON location: ', location); BackgroundGeolocation.endTask(taskKey); }); });
BackgroundGeolocation.headlessTask(async (event) => { if (event.name === 'location' || event.name === 'stationary') { const location = event.params; console.log(location); } });
BackgroundGeolocation.on('error', (error) => { console.log('[ERROR] BackgroundGeolocation error:', error); });
BackgroundGeolocation.on('start', () => { console.log('[INFO] BackgroundGeolocation service has been started'); });
BackgroundGeolocation.on('stop', () => { console.log('[INFO] BackgroundGeolocation service has been stopped'); });
BackgroundGeolocation.checkStatus(({ isRunning }) => { if (isRunning) { BackgroundGeolocation.start(); // service was running -> rebind all listeners } });