title: android - Bluetooth: program stuck at inputstream reading
body: <p>Helo. </p>
  
  <p>Im developing an application that transferes data over bluetooth(with a flight recorder device). When i am recieving a lot of data data(3000 - 40000 lines of text, depends of the file size) my aplication seems to stop recieving the data. I recieve the data with InputStream.read(buffer). For example: I send a command to the flight recorder, it starts sending me a file(line by line), on my phone i recieve 120 lines and then the app stucks.</p>
  
  <p>Intresting is that on my HTC Desire the app stucks just sometimes, on the Samsung Galaxy S phone the application stucks every single time i try to recive more than 50 lines.</p>
  
  <p>The code is based on the BluetoothChat example. This is the part of code where i am listening to the BluetoothSocket:</p>
  
  <pre><code>byte[] buffer = new byte[1024];
  int bytes =0;
  
  while(true)
  {
      bytes = mmInStream.read(buffer); 
      readMessage = new String(buffer, 0, bytes);
      Log.e("read", readMessage);
  
      String read2 = readMessage;
      //searching for the end of line to count the lines(the star means the start of the checksum)
      int currentHits = read2.replaceAll("[^*]","").length(); 
      nmbrOfTransferedFligts += currentHits;
      .
      .
      .
      //parsing and saving the recieved data         
  </code></pre>
  
  <p>I must say that i am running this in a while(true) loop, in a Thread, that is implemented in an android Service. The app seems to stuck at "bytes = mmInStream.read(buffer);"
  I have tried to do this with BufferedReader, but with no success.</p>
  
  <p>Thanks.</p>