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

[Android] GPS crash and shutdown after first location update received #10

Closed
vincenzoiacovone opened this issue Aug 30, 2016 · 23 comments
Closed

Comments

@vincenzoiacovone
Copy link

After first location update received, GPS shut down and stop working

  • Plugin version: 0.2.0-alpha.1
  • Platform: Android
  • OS version: 5.0.2
  • Device manufacturer and model: LG G2
  • React Native version: 0.32
  • Plugin configuration options:

BackgroundGeolocation.configure({
desiredAccuracy: 10,
stationaryRadius: 50,
distanceFilter: 10,
debug: false,
stopOnTerminate: false,
interval: 10000,
startOnBoot: false,
stopOnStillActivity: false
})

Expected Behavior

GPS still active receiving updates

Actual Behavior

GPS stop working after first update

Steps to Reproduce

  1. Configure plugin in componentWillMount
  2. Start
@vincenzoiacovone
Copy link
Author

vincenzoiacovone commented Aug 30, 2016

with locationProvider = 1 (activity) GPS works normally, but seems that interval number specified is not considered.

The problem of GPS crashing seems affect only locationProvider 0 (distance filter)

@BigPun86
Copy link

+1

@mauron85 mauron85 added the bug label Aug 31, 2016
@mauron85
Copy link
Owner

Can you post log of crash from adb logcat?

@mauron85
Copy link
Owner

mauron85 commented Aug 31, 2016

Ok, I've probably found problem. Just for confirmation. Does crash occur only after reload or it crashes also without reload?
https://facebook.github.io/react-native/docs/debugging.html#reloading-javascript

mauron85 added a commit that referenced this issue Sep 7, 2016
Android onStationary
Android getLogEntries
Android create gradle project
Android remove location filtering
Android db logging instead of file
mauron85 added a commit that referenced this issue Sep 7, 2016
Android onStationary
Android getLogEntries
Android create gradle project
Android remove location filtering
Android db logging instead of file
mauron85 added a commit that referenced this issue Sep 7, 2016
Android onStationary
Android getLogEntries
Android create gradle project
Android remove location filtering
Android db logging instead of file
@mauron85
Copy link
Owner

mauron85 commented Sep 7, 2016

Fixed crashed when app was reloaded from dev menu in "0.2.0-alpha.3". Reopen if necessary.

@mauron85 mauron85 closed this as completed Sep 7, 2016
@DanDance
Copy link

Have almost same problem.
App crashes after success callback of .start method.

  • Plugin version: 1.0.8
  • Platform: Android
  • OS version: 4.4.2
  • Device manufacturer and model: Alcatel One Touch P310X
  • React Native version: 0.28

Plugin configuration options:
BackgroundGeolocation.configure({
desiredAccuracy: 100,
stationaryRadius: 50,
distanceFilter: 50,
debug: false,
interval: 15000,
stopOnStillActivity: false,
stopOnTerminate: false,
maxLocations: 100
})

Expected Behavior

Plugin starts tracking device location, calls on('location') callback.

Actual Behavior

I can see console.log in .start success callback, .on('location') never called, app crashes.
adb logcat | grep BackgroundGeolocation shows

I/com.marianhello.react.BackgroundGeolocationModule(28598): App will be resumed
I/com.marianhello.react.BackgroundGeolocationModule(28598): App will be paused
I/com.marianhello.react.BackgroundGeolocationModule(28598): initializing plugin
I/com.marianhello.react.BackgroundGeolocationModule(28598): App will be resumed
I/com.marianhello.react.BackgroundGeolocationModule(28598): Requesting permissions from user
W/System.err(28598): at     com.marianhello.react.BackgroundGeolocationModule$1.onServiceConnected(BackgroundGeolocationModule.java:203)    
E/AndroidRuntime(28598):  at com.marianhello.react.BackgroundGeolocationModule$1.onServiceConnected(BackgroundGeolocationModule.java:203)

Steps to Reproduce

Configure plugin in componentWillMount
Handle .on('location')
.start with callback

@mauron85
Copy link
Owner

mauron85 commented Sep 14, 2016

Can you post full log? Few more lines will reveal full stacktrace. PS. Version 1.08 does not exist, which version are you using? PS2: Also upgrade to RN 0.33. Some issues related to this are fixed in 0.33

@DanDance
Copy link

I am sorry, version is 0.2.0-alpha.4.
I am afraid that upgrade to 0.33 will cause troubles with different plugins.

Full adb logcat is here:
http://pastebin.com/yEnNX0Se

@DanDance
Copy link

DanDance commented Sep 14, 2016

Here is adb logcat | grep com.marianhello. May be it could be useful.

D/ActivityThread(13398): SVC-Creating service:     CreateServiceData{token=android.os.BinderProxy@41f20440 className=com.marianhello.bgloc.LocationService packageName=com.driverapp intent=null}
D/ActivityThread(13398): SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@41f20440 className=com.marianhello.bgloc.LocationService packageName=com.driverapp intent=null}
D/ActivityThread(13398): SVC-SERVICE_ARGS handled : 0 / ServiceArgsData{token=android.os.BinderProxy@41f20440 startId=5 args=Intent { flg=0x4 cmp=com.driverapp/com.marianhello.bgloc.LocationService (has extras) }}
D/ActivityThread(13398): SVC-BIND_SERVICE handled : 0 / BindServiceData{token=android.os.BinderProxy@41f20440 intent=Intent { cmp=com.driverapp/com.marianhello.bgloc.LocationService (has extras) }}
E/AndroidRuntime(13398):    at com.marianhello.react.BackgroundGeolocationModule$1.onServiceConnected(BackgroundGeolocationModule.java:203)

/* Here I launch application*/

I/com.marianhello.react.BackgroundGeolocationModule(13569): initializing plugin
I/com.marianhello.react.BackgroundGeolocationModule(13569): App will be resumed
D/com.marianhello.bgloc.data.sqlite.SQLiteConfigurationDAO(13569): Configuration persisted with rowId = 1
I/com.marianhello.react.BackgroundGeolocationModule(13569): Requesting permissions from user
D/ActivityThread(13569): SVC-Creating service: CreateServiceData{token=android.os.BinderProxy@41ef9d50 className=com.marianhello.bgloc.LocationService packageName=com.driverapp intent=null}
I/com.marianhello.bgloc.LocationService(13569): Creating LocationService
D/ActivityThread(13569): SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@41ef9d50 className=com.marianhello.bgloc.LocationService packageName=com.driverapp intent=null}
D/ActivityThread(13569): SVC-Calling onStartCommand: com.marianhello.bgloc.LocationService@41e86cc8, flags=0, startId=6
I/com.marianhello.bgloc.LocationService(13569): Received start startId: 6 intent: Intent { flg=0x4 cmp=com.driverapp/com.marianhello.bgloc.LocationService (has extras) }
I/com.marianhello.bgloc.LocationService(13569): Network condition changed hasConnectivity: true
D/com.marianhello.bgloc.LocationService(13569): Will start service with: Config[distanceFilter=50 stationaryRadius=50.0 desiredAccuracy=100 interval=15000 fastestInterval=120000 activitiesInterval=10000 isDebugging=false stopOnTerminate=false stopOnStillActivity=false startOnBoot=false startForeground=true locationProvider=0 nTitle=Background tracking nText=ENABLED nIconLarge=null nIconSmall=null nIconColor=null url=null syncUrl=null syncThreshold=100 httpHeaders={} maxLocations=10000]
D/ActivityThread(13569): SVC-SERVICE_ARGS handled : 0 / ServiceArgsData{token=android.os.BinderProxy@41ef9d50 startId=6 args=Intent { flg=0x4 cmp=com.driverapp/com.marianhello.bgloc.LocationService (has extras) }}
D/ActivityThread(13569): SVC-BIND_SERVICE handled : 0 / BindServiceData{token=android.os.BinderProxy@41ef9d50 intent=Intent { cmp=com.driverapp/com.marianhello.bgloc.LocationService (has extras) }}
W/System.err(13569):    at com.marianhello.react.BackgroundGeolocationModule$1.onServiceConnected(BackgroundGeolocationModule.java:203)
E/AndroidRuntime(13569):    at com.marianhello.react.BackgroundGeolocationModule$1.onServiceConnected(BackgroundGeolocationModule.java:203)

@mauron85
Copy link
Owner

mauron85 commented Sep 14, 2016

Pastebin logs are useless, there is no crash there. And second one also. I need to 'see' after lines:

W/System.err(13569):    at com.marianhello.react.BackgroundGeolocationModule$1.onServiceConnected(BackgroundGeolocationModule.java:203)
E/AndroidRuntime(13569):    at com.marianhello.react.BackgroundGeolocationModule$1.onServiceConnected(BackgroundGeolocationModule.java:203)

Do not grep, because if filters out the most import part.

@DanDance
Copy link

@DanDance
Copy link

Upgrading React Native to 0.33.0 didn't solve the problem

@mauron85
Copy link
Owner

Ok last log was quite helpful. There is exception: java.lang.NoSuchFieldError: android.os.Message.sendingUid thrown in BackgroundGeolocationModule.java:203 which was added to API level 21 (Android 5.0) and you're on 4.4.2. Will try to find workaround for 4.4

mauron85 added a commit that referenced this issue Sep 15, 2016
@mauron85
Copy link
Owner

Please try installing from git branch issue10.

npm i https://github.com/mauron85/react-native-background-geolocation#issue10

@DanDance
Copy link

DanDance commented Sep 15, 2016

installed from https://github.com/mauron85/react-native-background-geolocation#issue10

Now it's not crashing. But after launching application .on('location') handler works only in the beginning. Sometimes debug says Stationary exit in 23.00349.

I want plugin to check my position every 15 sec. Am I doing something wrong?
Here is the code.

logError = (msg) => {
  console.log(`[ERROR] getLocations: ${msg}`);
  console.log(error)
}

BackgroundGeolocation.on('location', (location) => {
  console.log('[DEBUG] BackgroundGeolocation location', location);
});

BackgroundGeolocation.configure({
  desiredAccuracy: 10,
  stationaryRadius: 25,
  distanceFilter: 25,
  debug: true,
  interval: 15000,
  stopOnStillActivity: false,
  stopOnTerminate: false,
  maxLocations: 100
})
BackgroundGeolocation.start(() => {
    console.log('[DEBUG] BackgroundGeolocation started successfully');
  },
  (error) => {
    console.log('[ERROR] Start failed: ' + error.message);
  });

@mauron85
Copy link
Owner

That's how it works. It is using distance filter to save battery.. https://github.com/mauron85/cordova-plugin-background-geolocation/blob/master/ANDROID_DISTANCE_FILTER_PROVIDER.md

There is also another ANDROID_ACTIVITY_PROVIDER, which doesn't have distance filter. You can choose between those two.

https://github.com/mauron85/cordova-plugin-background-geolocation/blob/master/PROVIDERS.md

PS: need to copy these docs from cordova repo.

@vincenzoiacovone
Copy link
Author

vincenzoiacovone commented Sep 15, 2016

When i put the application in background and send location update (both emulator and real device), i've got this errors:

09-15 13:58:55.377 12111-12111/com.speedalert I/com.marianhello.react.BackgroundGeolocationModule: App will be paused 09-15 13:58:56.444 12111-12111/com.speedalert I/com.marianhello.react.BackgroundGeolocationModule: Destroying plugin 09-15 13:58:56.490 12111-12111/com.speedalert W/ViewPager: Requested offscreen page limit 0 too small; defaulting to 1 09-15 13:58:56.491 12111-12111/com.speedalert E/ActivityThread: Activity com.speedalert.MainActivity has leaked ServiceConnection com.marianhello.react.BackgroundGeolocationModule$1@2442b00f that was originally bound here android.app.ServiceConnectionLeaked: Activity com.speedalert.MainActivity has leaked ServiceConnection com.marianhello.react.BackgroundGeolocationModule$1@2442b00f that was originally bound here at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1077) at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:971) at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1774) at android.app.ContextImpl.bindService(ContextImpl.java:1757) at android.content.ContextWrapper.bindService(ContextWrapper.java:539) at com.marianhello.react.BackgroundGeolocationModule.doBindService(BackgroundGeolocationModule.java:477) at com.marianhello.react.BackgroundGeolocationModule.startAndBindBackgroundService(BackgroundGeolocationModule.java:442) at com.marianhello.react.BackgroundGeolocationModule.start(BackgroundGeolocationModule.java:277) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:319) at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:139) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:135) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196) at java.lang.Thread.run(Thread.java:818) 09-15 13:58:56.506 12111-12111/com.speedalert W/unknown:React: Tried to enqueue runnable on already finished thread: 'js... dropping Runnable. 09-15 13:58:56.508 12111-12111/com.speedalert W/MessageQueue: Handler (com.facebook.react.bridge.queue.MessageQueueThreadHandler) {1d720b54} sending message to a Handler on a dead thread java.lang.IllegalStateException: Handler (com.facebook.react.bridge.queue.MessageQueueThreadHandler) {1d720b54} sending message to a Handler on a dead thread at android.os.MessageQueue.enqueueMessage(MessageQueue.java:325) at android.os.Handler.enqueueMessage(Handler.java:631) at android.os.Handler.sendMessageAtTime(Handler.java:600) at android.os.Handler.sendMessageDelayed(Handler.java:570) at android.os.Handler.post(Handler.java:326) at com.facebook.react.bridge.queue.MessageQueueThreadImpl.runOnQueue(MessageQueueThreadImpl.java:61) at com.facebook.react.bridge.ReactContext.runOnJSQueueThread(ReactContext.java:247) at com.facebook.react.uimanager.events.EventDispatcher$ScheduleDispatchFrameCallback.doFrame(EventDispatcher.java:258) at com.facebook.react.uimanager.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:131) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:765) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:549) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

@mauron85
Copy link
Owner

@vincenzoiacovone are you using RN 0.33?

@vincenzoiacovone
Copy link
Author

I put the app in background using back button.

I use 0.32
Should i have to update the package?

@mauron85
Copy link
Owner

yes, it should be fixed with 0.33

@DanDance
Copy link

Hi again. On android 4.4.2 .watchLocationMode fail callback runs with Not implemented yet. Is there an opportunity to catch switch device gps to off?

@kholiavko-roman
Copy link

@DanDance , did you found the solution ?

@DanDance
Copy link

DanDance commented Sep 4, 2017

@kholiavko-roman with .watchLocationMode issue? Nope...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants