Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android app not releasing Bluetooth properly on exit

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

like image 994
T-basket Dotcodotuk Avatar asked Aug 16 '11 11:08

T-basket Dotcodotuk


1 Answers

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();
}
like image 177
Manish Singh Avatar answered Oct 26 '22 10:10

Manish Singh