When disconnects don't work as expected
You may have experienced a situation where programmatically requesting a disconnect does not work. Here are some reasons why that may happen.
You may have experienced a situation where programmatically requesting a disconnect does not work. Here are some reasons why that may happen.
- The BLE supervisor timeout may not have finished.
The supervisor's job is to make sure that the peripheral and central are talking to each other. After the central makes a disconnect request, the supervisor's timeout threshold has to be met in order for the connection to be truly severed.,
This threshold was 20s in early versions of Android - but was changed to 5s in newer versions but is still high (compared to <1s in iOS).
An excellent write-up on this can be found here close
was not called afterdisconnect
The BluetoothGatt handle will not fully clean up untilclose
is called afterdisconnect
This is the recommended approach per the documentationconnect
anddisconnect
are called too close together.
This may be a corner case for some apps, but there is a known issue where the Android Bluetooth stack can get into a strange place if not given time to complete connect/disconnect processing.