Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer start and configure until mService != null #7

Closed
wants to merge 2 commits into from

Conversation

danielgindi
Copy link
Contributor

@equesteo
Copy link

equesteo commented Jul 7, 2018

This does not solve #201 for me, I'm still getting a FATAL EXCEPTION when I close the app (from the switcher or by pressing the back button enough times to leave) and then attempt to load it again. I only turn on the location tracking when it's being used, not always when my app is open so it doesn't really make sense to me that it's trying to pause an activity on load (that's what the stack trace sounds like, I'm not totally clear). I get the following stack trace(s):

07-07 07:53:57.728 30506 30506 I com.marianhello.bgloc.react.BackgroundGeolocationModule: App will be paused
07-07 07:53:57.737 30506 30506 D AndroidRuntime: Shutting down VM
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: FATAL EXCEPTION: mainjava.lang.RuntimeException: Unable to pause activity {com.equesteo/com.reactnativenavigation.controllers.NavigationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3780)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3746)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3720)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3694)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.ActivityThread.-wrap16(ActivityThread.java)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1517)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.os.Handler.dispatchMessage(Handler.java:102)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.os.Looper.loop(Looper.java:154)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.ActivityThread.main(ActivityThread.java:6186)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at java.lang.reflect.Method.invoke(Native Method)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.marianhello.bgloc.BackgroundGeolocationFacade.switchMode(BackgroundGeolocationFacade.java:392)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.marianhello.bgloc.BackgroundGeolocationFacade.pause(BackgroundGeolocationFacade.java:283)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.marianhello.bgloc.react.BackgroundGeolocationModule.onHostPause(BackgroundGeolocationModule.java:113)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.facebook.react.bridge.ReactContext.onHostPause(ReactContext.java:212)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.facebook.react.ReactInstanceManager.moveToBeforeResumeLifecycleState(ReactInstanceManager.java:662)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.facebook.react.ReactInstanceManager.onHostPause(ReactInstanceManager.java:486)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.reactnativenavigation.react.NavigationReactGateway.onPauseActivity(NavigationReactGateway.java:79)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at com.reactnativenavigation.controllers.NavigationActivity.onPause(NavigationActivity.java:162)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.Activity.performPause(Activity.java:6824)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1323)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3769)
07-07 07:53:57.739 30506 30506 E com.marianhello.logging.UncaughtExceptionLogger: 	... 11 common frames omitted
07-07 07:53:57.761 30506 30506 E AndroidRuntime: FATAL EXCEPTION: main
07-07 07:53:57.761 30506 30506 E AndroidRuntime: Process: com.equesteo, PID: 30506
07-07 07:53:57.761 30506 30506 E AndroidRuntime: java.lang.RuntimeException: Unable to pause activity {com.equesteo/com.reactnativenavigation.controllers.NavigationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3780)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3746)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3720)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3694)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.ActivityThread.-wrap16(ActivityThread.java)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1517)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:102)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:154)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6186)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.marianhello.bgloc.BackgroundGeolocationFacade.switchMode(BackgroundGeolocationFacade.java:392)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.marianhello.bgloc.BackgroundGeolocationFacade.pause(BackgroundGeolocationFacade.java:283)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.marianhello.bgloc.react.BackgroundGeolocationModule.onHostPause(BackgroundGeolocationModule.java:113)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.facebook.react.bridge.ReactContext.onHostPause(ReactContext.java:212)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.moveToBeforeResumeLifecycleState(ReactInstanceManager.java:662)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.onHostPause(ReactInstanceManager.java:486)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.reactnativenavigation.react.NavigationReactGateway.onPauseActivity(NavigationReactGateway.java:79)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at com.reactnativenavigation.controllers.NavigationActivity.onPause(NavigationActivity.java:162)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.Activity.performPause(Activity.java:6824)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1323)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3769)
07-07 07:53:57.761 30506 30506 E AndroidRuntime: 	... 11 more

It seems like this has something to do with the provider I'm using, so here's how I'm configuring things:

    BackgroundGeolocation.configure({
      desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
      stationaryRadius: 10,
      distanceFilter: 10,
      maxLocations: 10,
      notificationTitle: 'You\'re out on a ride.',
      notificationText: 'Tap here to see your progress.',
      // debug: true,
      locationProvider: BackgroundGeolocation.RAW_PROVIDER,
      interval: 10000,
      fastestInterval: 5000,
      activitiesInterval: 10000,
    });

@danielgindi
Copy link
Contributor Author

It's a different issue! #201 is about calling configure when the service is not bound yet. Your exception is calling executeProviderCommand

@danielgindi
Copy link
Contributor Author

Although the solution could be similar - queue all sendCommands until the service is bound.
But I haven't seen this error so I can't test it and make a fix for it. You could do it :-)

@lorenc-tomasz
Copy link

@mauron85 When will you plan to merge it and release new version of React-Native plugin?

@mauron85
Copy link
Owner

mauron85 commented Aug 14, 2018

After quick look, it doesn't seem like proper fix for the problem. This PR just adds null checks, but as result one might call start or configure method and nothing happens.

@danielgindi
Copy link
Contributor Author

@mauron85 incorrect. It adds null checks - and defers the actions to later.
What happens is that you execute calls on null objects, while they will be available later.

@mauron85
Copy link
Owner

ok then. it could be merged as temporary solution

mauron85 pushed a commit that referenced this pull request Aug 16, 2018
@mauron85
Copy link
Owner

Merged. Thank you for your contribution!

@mauron85 mauron85 closed this Aug 16, 2018
mauron85 added a commit to mauron85/react-native-background-geolocation that referenced this pull request Aug 16, 2018
mauron85 added a commit to mauron85/cordova-plugin-background-geolocation that referenced this pull request Aug 16, 2018
@danielgindi
Copy link
Contributor Author

Thank YOU!

@danielgindi danielgindi deleted the patch-1 branch August 21, 2018 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants