Bluetoothchat Android input/output streams not closed
I have created an app that sends some data via bluetooth and my app was rebooting my device. And I found out it was down to the fact I was closing input and output streams when I was closing the bluetooth sockets ( I would close the streams then the sockets). And looking back at the bluetoothChat example found here http://developer.android.com/resources/samples/Bluetooth开发者_C百科Chat/index.html
they also never close their input/ output streams. Can any of you guys/gals help me as to why it is not needed to close the input/output streams or am I missing something.
I believe it's because when you close a stream, then any underlying stream or socket that was chained to it (that is, passed to its constructor) is closed as well.
http://www.javapractices.com/topic/TopicAction.do?Id=8
It's the same with a BufferedReader. When you close a BufferedReader, it will close whatever underlying stream / socket it has been used to 'wrap'. In fact I recently needed to have a BufferedReader that I could close without having it close the underlying stream, and to achieve this I had to extend BufferedReader and override close()
to perform no action.
try the sample you mentioned on your device, does it reboot your device? i think you are doing something wrong that eats the memory so the device reboots
精彩评论