Reedyuk / blue-falcon

A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android
https://bluefalcon.dev
Apache License 2.0
340 stars 45 forks source link

Android not calling close() method on BluetoothGatt when disconnecting #45

Closed kazyh closed 4 years ago

kazyh commented 4 years ago

It is propably only android issue

When calling connect and disconnect device several times during one app session GattCallbacks are aggregated and I get multiplied callbacks about characteristic changed.

This happens because in BluetoothGatt.connect (it is called by BluetoothDevice.connectGatt in BlueFalcon.connect) callback is registered. But BlueFalcon.disconnect method calling only BluetoothGatt.disconnect and should also call BluetoothGatt.close (in close() method callback is unregistered).

kazyh commented 4 years ago

It will also solve problem with double didDisconnect call (didDisconnect is called direct from bluefalcon disconnect method and it is called again when gattCallbeck.onConnectionStateChange notify about newState == STATE_DISCONNECTED ) .

If BluetoothGatt.close() would be called in disconnect method it will prevent from any callbacks from disconnected device.

Reedyuk commented 4 years ago

ok sounds logical, i will look into it. - PR's always welcome.

Reedyuk commented 4 years ago

Issue has been closed, please checkout release 0.7.2