0
votes

I am trying to connect to devices via bluetooth. When I hit the search button everything is good. Also when I click the device from the Detected Devices list also they get paired correctly. But when I click the desired device from the Paired Devices list to connect, firstly the are connected but after ~5 seconds they disconnect and stay paired.Also the socket closes...This is what I get: enter image description here

The code is : here

1

1 Answers

0
votes

firstly the are connected but after ~5 seconds they disconnect and stay paired.

If your device is Bluetooth low energy device, well, it is what Bluetooth LE designed to be. Unlike classical Bluetooth, Bluetooth LE keep connection for very short period of time. After data exchange complete, current connection end immediately. Connection will be established again when there is data to exchange next time.

If the problem isn't caused by Bluetooth designing then it should be caused by your code itself. In your post we can see:

The application may be doing too much work on its main thread.

What this means is that your code is taking long to process and frames are being skipped because of it, It maybe because of some heavy processing that you are doing at the heart of your application or DB access or any other thing which causes the thread to stop for a while.

How to fix it?

The best way is to do all the processing no matter how small or big in a thread separate from main UI thread. A comprehensive explanation is here.