react-native-background-geolocation: App still use location data even after Background.stop() and then sometimes it crashed.
Your Environment
- Plugin version: 0.5.0
- Platform: Android
- OS version: Detected on android 7,8,9
- Device manufacturer and model: Samsung, LG, …
- Running in Simulator: No
- React Native version: 0.58.5
- Plugin configuration options:
BackgroundGeolocation.configure({
locationProvider: BackgroundGeolocation.DISTANCE_FILTER_PROVIDER,
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 3,
debug: false,
distanceFilter: 3,
stopOnTerminate: true,
startOnBoot: false,
interval: 3000,
fastestInterval: 3000,
activitiesInterval: 3000,
startForeground: false,
notificationTitle: 'Tracking',
notificationText': 'Tracking!",
notificationsEnabled: false,
pauseLocationUpdates: false,
saveBatteryOnBackground: false,
url: URL,
postTemplate: this.generatePostTemplate(null)
});
generatePostTemplate(customValue) {
return {
latitude: '@latitude',
longitude: '@longitude',
inputLoggedAt: '@time',
accuracy: '@accuracy',
customValue: customValue,
os: 'Android'
};
}
reConfigure = () => {
// When user login, and when customValue changes,
// I call this function to re-configure the geolocation configuration.
const loginUser = this.rootStore.userStore.loginUser;
const customValue = this.rootStore.customStore.customValue;
const options: Partial<ConfigureOptions> = {};
if (loginUser) {
options.httpHeaders = {
Authorization: `Token ${loginUser.authToken}`
};
}
if (customValue) {
options.postTemplate = this.generatePostTemplate(customValue);
}
BackgroundGeolocation.configure(options);
if (customValue === null) {
// I don't need geolocation tracking when customValue is null.
BackgroundGeolocation.stop();
}
};
- Link to your project:
Context
What I need is tracking geolocation(foreground, background) only between I call BackgroundGeolocation.start, and stop. I don’t need sync location of failed data. Only the data between calling start and stop are all I need.
App works great when I start the app, start geolocation and stop geolocation. It works what I expected. However, after couple of hours while app is in background, even I never call BackgroundGeolocation.start(), app starts to use location data(There was a pin marker in android status bar, and when I terminated the app, it disappeared.) and then, app crash again and again.(When app crash, android alert modal appears and there were two selections. Close app, Send comment. Even I press close app, the modal appears again and again.) Also, there was a notification “Sync Location”. After I set “notificationEnabled” to false, the “Sync Location” notification disappear, but still app crash again and again after couple of hours.
I think app try to sync location even after I call BackgroundGeolocation.stop() and even I didn’t set syncUrl configuration. (The url I set in configuration always return 200, 201 status.)
Expected Behavior
App don’t track geolocation before I call start.
Actual Behavior
App use geolocation data and crash even I never call start.
Possible Fix
Steps to Reproduce
- Start app(not even start geolocation)
- go to background
- after couple of hours
Context
Debug logs
This is a crash report. I think this crash report may be related.
java.lang.IllegalStateException: Not allowed to start service Intent { cmp=kr.oshare.alpaca/com.marianhello.bgloc.service.LocationServiceImpl (has extras) }: app is in background uid UidRecord{6c02e96 u0a240 CRE bg:+4m26s253ms idle procs:1 proclist:19827, seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1666)
at android.app.ContextImpl.startService(ContextImpl.java:1611)
at android.content.ContextWrapper.startService(ContextWrapper.java:677)
at com.marianhello.bgloc.service.LocationServiceProxy.executeIntentCommand(LocationServiceProxy.java:93)
at com.marianhello.bgloc.service.LocationServiceProxy.stop(LocationServiceProxy.java:58)
at com.marianhello.bgloc.BackgroundGeolocationFacade.stopBackgroundService(BackgroundGeolocationFacade.java:440)
at com.marianhello.bgloc.BackgroundGeolocationFacade.destroy(BackgroundGeolocationFacade.java:264)
at com.marianhello.bgloc.react.BackgroundGeolocationModule.onHostDestroy(BackgroundGeolocationModule.java:125)
at com.facebook.react.bridge.ReactContext.onHostDestroy(ReactContext.java:228)
at com.facebook.react.ReactInstanceManager.moveToBeforeCreateLifecycleState(ReactInstanceManager.java:687)
at com.facebook.react.ReactInstanceManager.onHostDestroy(ReactInstanceManager.java:596)
at com.facebook.react.ReactInstanceManager.onHostDestroy(ReactInstanceManager.java:610)
at com.facebook.react.ReactActivityDelegate.onDestroy(ReactActivityDelegate.java:122)
at com.facebook.react.ReactFragmentActivity.onDestroy(ReactFragmentActivity.java:73)
at android.app.Activity.performDestroy(Activity.java:7680)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1306)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4667)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4700)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:39)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
java.lang.RuntimeException: Unable to destroy activity {kr.oshare.alpaca/kr.oshare.alpaca.MainActivity}: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=kr.oshare.alpaca/com.marianhello.bgloc.service.LocationServiceImpl (has extras) }: app is in background uid UidRecord{6c02e96 u0a240 CRE bg:+4m26s253ms idle procs:1 proclist:19827, seq(0,0,0)}
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4682)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4700)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:39)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 85 (29 by maintainers)
We’re getting the same sort of crash reports from Bugsnag when users are closing our application. I haven’t been able to reproduce the crash myself, but there have been multiple reports like this after upgrading from React Native 0.57.something to the newest ones, currently at 0.59.9.
Here’s the crash report from Bugsnag:
Unable to destroy activity {mypackage/myapp.MainActivity}: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=mypackage/com.marianhello.bgloc.service.LocationServiceImpl (has extras) }: app is in background uid UidRecord{842ac30 u0a210 CEM bg:+2h41m8s344ms idle procs:1 proclist:31355, seq(0,0,0)}
All of these reports have been from users that are on Android 9.
I’m using version 0.5.3 of this package. @mauron85 any idea of what could be causing this? I haven’t changed anything in my own code, and in the previous versions of RN this bug was not present.
Here’s also a piece of the stacktrace (from bottom to top), crash happens at the top.
--- report sent here (Unable to destroy...) ContextImpl.java:1666android.app.ContextImpl.startServiceCommon ContextImpl.java:1611android.app.ContextImpl.startService ContextWrapper.java:677android.content.ContextWrapper.startService LocationServiceProxy.java:104com.marianhello.bgloc.service.LocationServiceProxy.executeIntentCommand LocationServiceProxy.java:65com.marianhello.bgloc.service.LocationServiceProxy.stop BackgroundGeolocationFacade.java:440com.marianhello.bgloc.BackgroundGeolocationFacade.stopBackgroundService BackgroundGeolocationFacade.java:264com.marianhello.bgloc.BackgroundGeolocationFacade.destroy BackgroundGeolocationModule.java:125com.marianhello.bgloc.react.BackgroundGeolocationModule.onHostDestroy
Running into the same issue. Lots of crash reports coming in but so far I haven’t been able to reproduce anything. @AE0011 that version doesn’t exist and will use
0.5.3
.We’re only seeing this in Android 9.
Ok, reopening then. But I’m afraid I cannot help here.
@juusopitkanen : which resolve this issue ??? I have same error.
@juusopitkanen. It probably worked because older Android SDK didn’t have that restrictrion about not starting service from the background. And newer RN migrated to newer SDK so the problem started to occur.
@mauron85 : i have the same issue, app still using location service after stop service, so if user select whenInUse permission, there is label notice to user that app’s using location on app background. I used v0.5.3 as you said above but it still happen. So any solution for this issue ? thanks !!!
+1, this is also happening to me in production. Sometimes the notification in the bar will be my custom notification, and sometimes it will just say something like “Background Tracking”.
I am on 0.5.0-alpha.50