From 1d1672e3b9ccfbde2c2998c3b27f18a0b09768c0 Mon Sep 17 00:00:00 2001 From: Vitaly Chekryzhev <13hakta@gmail.com> Date: Thu, 21 Jan 2016 17:51:01 +0900 Subject: BluetoothChat: Fix crash on disconnection https://github.com/googlesamples/android-BluetoothChat/pull/1 Update BluetoothChatService.java Read input stream only when connection established. Otherwise there will be exceptions on disconnection and disconnection when program finish. Change-Id: I4fb93cee93c271d2159c7811a83474699eb3ae0b --- .../java/com/example/android/bluetoothchat/BluetoothChatService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectivity/bluetooth/BluetoothChat/Application/src/main/java/com/example/android/bluetoothchat/BluetoothChatService.java b/connectivity/bluetooth/BluetoothChat/Application/src/main/java/com/example/android/bluetoothchat/BluetoothChatService.java index b88b160d..a1e7cc01 100644 --- a/connectivity/bluetooth/BluetoothChat/Application/src/main/java/com/example/android/bluetoothchat/BluetoothChatService.java +++ b/connectivity/bluetooth/BluetoothChat/Application/src/main/java/com/example/android/bluetoothchat/BluetoothChatService.java @@ -473,7 +473,7 @@ public class BluetoothChatService { int bytes; // Keep listening to the InputStream while connected - while (true) { + while (mState == STATE_CONNECTED) { try { // Read from the InputStream bytes = mmInStream.read(buffer); -- cgit v1.2.3