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.

  1. 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
  2. close was not called after disconnect
    The BluetoothGatt handle will not fully clean up until  close is called after disconnect

    This is the recommended approach per the documentation  
  3. connect and disconnect 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.