title: Does the number of bytes slows the Bluetooth receiving proccess on Android?
body: <p>I'm building an Android app that sends and receives values from Arduno, using Bluetooth. The Arduino sends the String "OBJECT_FOUND" when a ultrasonic sensor founds an object near by.</p>
  
  <p>I'm using a code taken from a Tutorial. Sometimes, is possible to see the values sent by arduino while the ultrasonic sensor is in front of an object, but It takes too long to receive the data, and most of the time is not possible to see the sent values. The time is crucial for the functioning of my system, and I would like to receive the data in real time. </p>
  
  <p>Here's the code:</p>
  
  <pre><code>public void beginListenForData() {
      final Handler handler = new Handler();
      final byte delimiter = 10; //This is the ASCII code for a newline character
  
      stopWorker = false;
      readBufferPosition = 0;
      readBuffer = new byte[1024];
      workerThread = new Thread(new Runnable() {
          public void run() {
              while (!Thread.currentThread().isInterrupted() &amp;&amp; !stopWorker) {
                  try {
                      int bytesAvailable = mmInputStream.available();
                      if (bytesAvailable &gt; 0) {
                          byte[] packetBytes = new byte[bytesAvailable];
                          mmInputStream.read(packetBytes);
                          for (int i = 0; i &lt; bytesAvailable; i++) {
                              byte b = packetBytes[i];
                              if (b == delimiter) {
                                  byte[] encodedBytes = new byte[readBufferPosition];
                                  System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
                                  final String data = new String(encodedBytes, "US-ASCII");
                                  readBufferPosition = 0;
  
                                  handler.post(new Runnable() {
                                      public void run() {
                                          if (data.equals("OBJECT_FOUND")) {
                                              anyObject = true;
                                          } else {
                                              anyObject = false;
                                          }
                                      }
                                  });
                              } else {
                                  readBuffer[readBufferPosition++] = b;
                              }
                          }
                      }
                  } catch (IOException ex) {
                      stopWorker = true;
                  }
              }
          }
      });
  
      workerThread.start();
  }
  </code></pre>
  
  <p>Should I avoid the sending a "big" string, and send only 0's and 1's to increase the proccess?</p>
  
  <p>The lag can be cause by another problem, I'm trying to figured out what's the problem.</p>
  
  <p>Thank you.</p>