react-native-background-geolocation
react-native-background-geolocation copied to clipboard
App crashes randomly - java.lang.IllegalStateException
Your Environment
- Plugin version: 4.4.4
- Platform: Android
- OS version: Android 11 (SDK 30)
- Device manufacturer / model: Google Pixel 6
- React Native version (
react-native -v
): 0.65.1 - Plugin config
BackgroundGeolocation.ready(
{
// Geolocation Config
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
// Activity Recognition
stopTimeout: 1,
stationaryRadius: 50,
// Application config
debug: false, // <-- enable this hear sounds for background-geolocation life-cycle.
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
// HTTP / SQLite config
url: `${config.url}/locationhistorybackground`,
batchSync: true, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
autoSyncThreshold: 5,
enableHeadless: true,
locationAuthorizationRequest: "Always",
backgroundPermissionRationale: {
title:
"Allow sBizzl to access this device's location even when closed or not in use?",
message:
"sBizzl will use location in the background to show current location activities on a map. sBizzl collects location data only when you are clocked-in."
},
locationTemplate:
'{"latitude":<%= latitude %>,"longitude":<%= longitude %>,"event":"<%= event %>","isMoving":<%= is_moving %>,"accuracy":<%= accuracy %>,"datetime":"<%= timestamp %>","speed":<%= speed %>,"heading":<%= heading %>}',
headers: {
// <-- Optional HTTP headers
"Content-Type": "application/json",
token: user.token
},
params: {
// <-- Optional HTTP params
clocking: clockingData
}
},
(state) => {
if (!state.enabled) {
////
// 3. Start tracking!
//
BackgroundGeolocation.start(function () {
// console.log("- Start success");
});
}
}
);
Expected Behavior
App should work without crashing
Actual Behavior
App crashes in the background
Steps to Reproduce
Can't re-produce it, it's a production issue.
Context
Debug logs
Logs
Exception java.lang.IllegalStateException: Tried to access a JS module before the React instance was fully set up. Calls to ReactContext#getJSModule should only happen once initialize() has been called on your native module.
at com.facebook.react.bridge.ReactContext.getJSModule (ReactContext.java:161)
at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.sendEvent (RNBackgroundGeolocationModule.java:1047)
at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.access$1400 (RNBackgroundGeolocationModule.java:69)
at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule$LocationProviderChangeCallback.onLocationProviderChange (RNBackgroundGeolocationModule.java:205)
at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$i0.run
at android.os.Handler.handleCallback (Handler.java:883)
at android.os.Handler.dispatchMessage (Handler.java:100)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:7405)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:502)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:980)