public void run() { while (true) { if (socket != null) { try { int read = -1; byte buffer[] = new byte[1024]; InputStream inputStream = BluetoothService.socket.getInputStream(); for (; (read = inputStream.read(bytes)) > -1;) { final int count = read; synchronized (BluetoothService.receiveData) { for (int i = 0; i < count; i++){ BluetoothService.receiveData.add(buffer[i]); } } } } catch (Exception e) { BluetoothService.connected = false; } try { Thread.sleep(300); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }