title: How to clear the bluetooth InputStream buffer
body: <p>In the bluetoothChat example app, the sent and received data is added into a ArrayAdapter called <code>mConversationArrayAdapter</code>. There, each character is added into the array.</p>
  
  <p>In my case, I have a String instead of an array because I don't need to send and receive several data, I only need to send one string, and receive one string each time.</p>
  
  <p>The problem that I'm getting is that if I first receive a string like <code>hello world</code>, and then I receive a shorter one, the first is overwrited by the second, instead of deleting the first and writing the new.</p>
  
  <p>So, if i first receive <code>hello world</code>, and then I supposse that I have to receive <code>bye</code>, what I really receive is <code>byelo world</code>.</p>
  
  <p>So, how can I clear the buffer each time a receive what I want?</p>
  
  <p><strong>Code Snipets</strong></p>
  
  <p>Send data:</p>
  
  <pre><code>    byte[] send1 = message_full1.getBytes();
      GlobalVar.mTransmission.write(send1);
  </code></pre>
  
  <p>Write call:</p>
  
  <pre><code>public void write(byte[] out) {
      /**Create temporary object*/
      ConnectedThread r;
      /**Synchronize a copy of the ConnectedThread*/
      synchronized (this) {
          if (GlobalVar.mState != GlobalVar.STATE_CONNECTED) return;
          r = GlobalVar.mConnectedThread;
      }
      /**Perform the write unsynchronized*/
      r.write(out);
  }
  </code></pre>
  
  <p>Write Thread:</p>
  
  <pre><code>    public void write(byte[] buffer) {
      try {
          GlobalVar.mmOutStream.write(buffer);
  
          /**Share the sent message back to the UI Activity*/
          GlobalVar.mHandler.obtainMessage(GlobalVar.MESSAGE_WRITE, -1, -1, buffer).sendToTarget();
  
      } catch (IOException e) {}
  }
  </code></pre>
  
  <p>Finally, read Thread:</p>
  
  <pre><code>    public void run() {
      byte[] buffer = new byte[12];  // buffer store for the stream
      int bytes; // bytes returned from read()
  
      /**Keep listening to the InputStream until an exception occurs*/
      while (true) {
          try {
              /**Read from the InputStream*/
              bytes = GlobalVar.mmInStream.read(buffer);
  
              /**Send the obtained bytes to the UI activity*/
              GlobalVar.mHandler.obtainMessage(GlobalVar.MESSAGE_READ, bytes, -1, buffer).sendToTarget();
          } catch (IOException e) {
              GlobalVar.mTransmission.connectionLost();
              /**Start the service over to restart listening mode*/
              //GlobalVar.mTransmission.start();
              break;
          }
      }
  }
  </code></pre>