I'm in desperate need of a solution to this issue, for some reason on another device i have tested my bluetooth app on, when i close the app (onDestroy()) and reenter it the bluetooth connections fail. The only solution to this currently is to turn bluetooth off and on for the device.
The code i use is more or less the bluetoothchat sample for android. I create 2 bt connections to a device previously selected.
I then communicate back and forth with these sockets using inputstream and output stream.
When my app is destroyed - i close input and output and bluetooth sockets, I even then kill the process (found some code on here) but when i go back into the app the connection fails.
Can anyone offer any assistance from what i said so far? My code is quite a lot at the moment so wouldnt know what to paste but the bt connection is basically using the classes from the sample and then passing these created sockets to my other classes.
Thanks in advance
The best way to use onDestroy is in following manner, hope you are doing something similar.
@Override
protected void onDestroy() {
if (localBT != null) {
localBT.close();
}
super.onDestroy();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With