Android Bluetooth Crashes Application When Remote Device Closes Socket
I have connected my Android application to a Windows desktop machine via Bluetooth. The application interacts with the machine. At the end of the interaction the application on the desktop closes the socket that was opened between开发者_StackOverflow社区 the Android and the desktop application.
Right when socket.close() is called on the Windows machine my Android app pops open a dialog saying that the application has stopped unexpectedly and then it quits. I have a breakpoint on the line in the ConnectedThread (like in the BluetoothChat sample) where I read the InputStream on the Android and that is not hit. I also have a breakpoint in the catch statement for the try surrounding the place where I read the InputStream. That one also does not get hit. So I have no idea how I can catch this error. Is this a bug?
Can anyone give me a hand? Thanks!
I just use the standard connect method. I was using some of the stock code from a sample which was not entirely optimal for what I was doing anyway, so I rewrote the loop that accepted the data. And now the bug has gone away. I am not sure what caused it since the sample code seemed quite short and clean. But now it works perfectly.
精彩评论