react-native-background-geolocation: Android headless mode not working / crashing
Your Environment
- Plugin version: 4.10.0
- Platform: Android
- OS version: Android 11
- Device manufacturer / model: HONOR X8
- React Native version (
react-native -v): 0.70.6 - Plugin config
{
allowIdenticalLocations: false,
autoSync: false,
batchSync: false,
debug: true,
desiredAccuracy: Platform.OS === 'android' ? BackgroundGeolocation.DESIRED_ACCURACY_VERY_LOW : BackgroundGeolocation.DESIRED_ACCURACY_LOWEST,
desiredOdometerAccuracy: 10,
disableElasticity: true,
disableProviderChangeRecord: true,
distanceFilter: 500,
enableHeadless: true,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
startOnBoot: false,
stationaryRadius: 300,
stopOnTerminate: false,
stopTimeout: 5,
triggerActivities: 'in_vehicle'
}
Expected Behavior
The tracking should continue when app is killed and registered task should always get executed
Actual Behavior
When user kills the app, sometime it passes though the registered task function and i get some event like ‘connectivityChange’ and ‘terminate’ but after 5/10 seconds, it crashes and no event are triggered anymore. The crash error is explicit but cannot figure out why. Sometime it does not even enter the registered task function.
Steps to Reproduce
- Open the app, start tracking after initialization is done
- Kill the app
Context
The goal is to keep tracking location when the app is killed, working fine on ios but not on android.
Debug logs
Logs when registered tasks is executed and crashes
In comment because of the limite i could not add them in the issueAbout this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (7 by maintainers)
And, like I said: “you can simulate moving while sitting at your desk and simply shaking the device vigorously.” You don’t need to go outside for this sort of test
I’d probably also disable all my code I’m expecting to run in my headless task and do
BackgroundGeolocation.loggermessage in there (see api docs). Then I’d go for a field test and fetch my logs with.emailLog(myEmail)to see if my headless log messages are there in the logs. Then I’d conclude there’s nothing wrong with the plugin and that the custom code in the HeadlessTask is at fault.You need to physically move with the device before the plugin will turn on location-services and record locations.
you can simulate moving by shaking the device vigorously to simulate walking (can take some time, typically 10-30s of shaking).
i suggest you observe
$ adb logcat *:S TSLocationManager:Vwhile doing so.