Repository navigation
FAQ_Technical
http://idevicesinc.com/sweetblue/docs/api/
Yes, this was one of the primary purposes for its creation.
Doing multi-threading in Java can be a huge source of bugs, so we made a deliberate decision to force the API such that it can only be called from the main thread (similar to Android's View library), and operation results are posted back to the main thread through asynchronous callbacks only. The model should be very familiar if you have any experience with JavaScript, for example. Under the hood of course SweetBlue does some multi-threading, but this is all hidden from you.
In order to understand some of the decisions behind reconnect logic, one must first understand that disconnects can happen very frequently on Android even under the best of conditions. You may sometimes gets disconnects every few seconds even though you can trivially reconnect immediately afterwards.
So, when a disconnect occurs a BleDevice enters a state called RECONNECTING_SHORT_TERM. See docs here:
What this means is that SweetBlue temporarily hides the fact that the device actually disconnected while it tries to silently reconnect for several seconds. If this silent reconnection fails, a BleDevice notifies your app code of the disconnect and enters a state called:
This means the device will automatically try connecting again and again until, e.g. it comes back into range. Overall by default SweetBlue is pretty aggressive about reconnecting due to how often random disconnects can occur even under the best of conditions. The short term reconnect is meant to hide the annoying transient disconnects from you, while the long term is a convenience to re-establish connection after legitimate disconnects (e.g. from out of range) as soon as possible.
You can control the reconnect behavior through the following if the defaults don’t work for your situation:
http://idevicesinc.com/sweetblue/docs/api/com/idevicesinc/sweetblue/BleDeviceConfig.html#reconnectPersistFilter_longTerm http://idevicesinc.com/sweetblue/docs/api/com/idevicesinc/sweetblue/BleDeviceConfig.html#reconnectRequestFilter_longTerm http://idevicesinc.com/sweetblue/docs/api/com/idevicesinc/sweetblue/BleDeviceConfig.html#reconnectPersistFilter_shortTerm http://idevicesinc.com/sweetblue/docs/api/com/idevicesinc/sweetblue/BleDeviceConfig.html#reconnectRequestFilter_shortTerm
