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

Make sure mService exists when we call start or stop #17

Merged
merged 3 commits into from
Sep 29, 2018

Conversation

ivosabev
Copy link
Contributor

@ivosabev ivosabev commented Sep 25, 2018

This handles the crash where mService has been killed or not initialized at all and the stop() method is called on a null value.

Examples:

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.start()' on a null object reference
com.marianhello.bgloc.BackgroundGeolocationFacade.startBackgroundService
Unable to destroy activity {com.xxx.yyy/com.xxx.yyy.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.stop()' on a null object reference
android.app.ActivityThread.performDestroyActivity

@ivosabev ivosabev changed the title Make sure mService exists when we call stop() Make sure mService exists when we call start or stop Sep 25, 2018
@mauron85
Copy link
Owner

mauron85 commented Sep 26, 2018

Ok, thanks. It will be merged. However this is just fixing symptoms. Fundamental question is why mService becomes null.

@ivosabev
Copy link
Contributor Author

ivosabev commented Sep 27, 2018

I haven't got to time extensively test what exactly causes this, but I think it is because the current code doesn't account about the fact that the service could stop unexpectedly between the BackgroundGeolocationFacade.stop() call and the actual BackgroundGeolocationFacade. stopBackgroundService() meaning that onServiceDisconnected() might be called and the service could become null.

Also it is not accounted about the fact that binder.getService() might return null in onServiceConnected(). For example in the BackgroundGeolocationFacade.stop() you check for mService being null, but still call the stopBackgroundService() even if it is null.

@mauron85 mauron85 merged commit 08374b8 into mauron85:master Sep 29, 2018
@mauron85
Copy link
Owner

Merged. Thanks.

mauron85 added a commit to mauron85/react-native-background-geolocation that referenced this pull request Sep 29, 2018
mauron85 added a commit to mauron85/cordova-plugin-background-geolocation that referenced this pull request Sep 29, 2018
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.

2 participants