When disconnecting from a device you invoke gatt.disconnect() and immediately after gatt.close(). What this does is that it doesn't allow the bluetooth stack to send in time an onConnectionStateChange message to the GattCallback.
If you remove the gatt.close() command from the AndroidBle disconnect method and append it to the if (newState == BluetoothProfile.STATE_DISCONNECTED) path in onConnectionStateChange all goes well.
Often, before I modified the code, I would receive from time to time some NullPointerException from the onConnectionStateChange implementation. After the change the code runs ok.
When disconnecting from a device you invoke
gatt.disconnect()
and immediately aftergatt.close()
. What this does is that it doesn't allow the bluetooth stack to send in time anonConnectionStateChange
message to the GattCallback.If you remove the gatt.close() command from the AndroidBle disconnect method and append it to the
if (newState == BluetoothProfile.STATE_DISCONNECTED)
path inonConnectionStateChange
all goes well.Often, before I modified the code, I would receive from time to time some NullPointerException from the
onConnectionStateChange
implementation. After the change the code runs ok.