xpg / GizwitsBLE

Android BLE SDK
Apache License 2.0
195 stars 89 forks source link

Issue on Android BLE disconnect #10

Open bogdandynamic opened 7 years ago

bogdandynamic commented 7 years ago

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.