Estimote / Android-Fleet-Management-SDK

Estimote Fleet Management SDK for Android
https://developer.estimote.com
MIT License
836 stars 451 forks source link

How to run from worker thread? #220

Closed c-h- closed 7 years ago

c-h- commented 7 years ago

Hello, I've included the Estimote Android SDK in a React Native Android app. The problem though is that the SDK appears to require being run on the main thread rather than a worker thread (where React Native native modules are run from).

Is there some way to include the SDK as a native module for React Native android? Or at least some way to get the SDK running from a worker thread (and I can bundle it as a native module for RN Android from there)?

Why does the SDK require being executed on the main thread? If the SDK was open source this would be much simpler to understand.

This is the error I get: Estimote SDK 1.0.3

Exception in native call
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)
        at android.os.Handler.<init>(Handler.java:114)
        at com.estimote.coresdk.service.BeaconManager$IncomingHandler.<init>(BeaconManager.java:1008)
        at com.estimote.coresdk.service.BeaconManager$IncomingHandler.<init>(BeaconManager.java:1008)
        at com.estimote.coresdk.service.BeaconManager.<init>(BeaconManager.java:316)
        at com.estimoteTeeth.EstimoteTeethManager.<init>(EstimoteTeethManager.java:21)
        at com.estimoteTeeth.EstimoteTeethModule.<init>(EstimoteTeethModule.java:36)
        at com.estimoteTeeth.EstimoteTeethPackage.createNativeModules(EstimoteTeethPackage.java:18)
        at com.facebook.react.XReactInstanceManagerImpl.processPackage(XReactInstanceManagerImpl.java:958)
        at com.facebook.react.XReactInstanceManagerImpl.createReactContext(XReactInstanceManagerImpl.java:879)
        at com.facebook.react.XReactInstanceManagerImpl.access$600(XReactInstanceManagerImpl.java:110)
        at com.facebook.react.XReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(XReactInstanceManagerImpl.java:214)
        at com.facebook.react.XReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(XReactInstanceManagerImpl.java:193)
        at android.os.AsyncTask$2.call(AsyncTask.java:288)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
pawelDylag commented 7 years ago

Hello @c-h-

Sorry for the late response. We didn't prepare our SDK to be interoperable with React Native yet. We need to apply proper fixes and change architecture a little bit to match such cases. I'll keep you informed about the progress - maybe not this month, but in a close future :)

Cheers!

c-h- commented 7 years ago

Thanks @pawelDylag I'll be watching in anticipation!