

Bluetooth Low Energy on Android - msemenistyi
http://binary-studio.com/2014/08/29/bluetooth-low-energy-for-android-part-1/

======
lunaticlabs
Although not heavily emphasized in this article, nor in the documentation, the
serial nature of this library is very important. The android BLE library is
asynchronous in its callback nature, but it does not contain any sort of
automatic queuing mechanism for requests. If you call to start a scan, for
example, and during that scan make a connection attempt, due to the
synchronous nature, the connect request can abort the scan without providing a
scan error callback. This can catch you the other way too, if you initiate a
scan while a connection is pending, the connection request will silently
abort. An addition complexity to be wary of is that a failed connection
request may not call back consistently, so setting up your own queuing is not
always straightforward. If you are developing a new application for android
that uses bluetooth, be very careful in setting up this queuing mechanism
ahead of time, as it can be functionally difficult to implement later on. If
you are going to connect to multiple devices, you are even more likely to run
into these sorts of issues. The way I have my application setup for device
scan and pairing, as an example, is to scan for some period of time (roughly
5-10 seconds), after which I end the scan, and then process any pending
connections. Once the connections have been completed (in a serial fashion), I
then restart the scan. This behavior may have been updated in android 5.x, but
is definitely an issue to be wary of in android version 4.x

