I stop getting onCharacteristicChanged after exiting the app and restarting it.
Here are the steps I did pairing to a ble device.
- I have a service that contains the ble logic and persist the
bluetoothGatthobj, I perform ablueToothGatt.connecthere on app launch. - Once I get
onConnectionStateChangewithSTATE_CONNECTED, I callblueToothGatt.discover - On the
onServicesDiscoveredcallback, I will fetch and persist the services and characteristics that I care about. Then I will callblueToothGatt.setCharacteristicNotificationand write to descriptor to enable notification. - Now I perform a write and then I will get callback for
onCharacteristicChangejust fine. - After this, say I exit the app (device is still paired). The
onDestroyof the last activity, my ble device service gets unbind...in which I will perform close onunbindcallback and callselfstopto stop the service. Now if I relaunch the app. I will do the same steps 1-4, however this time aroundonCharacteristicChangedoes not get call, also I tried disconnect before close...but that didn't help
(One thing that I do notice is that if the device is left unpaired/disconnected upon relaunch then the issue occurs, however if I power of the BLE device off and turn it back on before restarting the app, then I get the callback onCharacteristicChanged just fine. This seems like the device is holding onto some setting that prevents onCharacteristics to get call.)
Any insights to this will be greatly appreciated. Thanks!