Cómo borrar el búfer de InputStream bluetooth

En la aplicación de ejemplo bluetoothChat, los datos enviados y recibidos se agregan a un ArrayAdapter denominado mConversationArrayAdapter . Allí, cada carácter se agrega a la matriz.

En mi caso, tengo una cadena en lugar de una matriz porque no necesito enviar y recibir varios datos, sólo necesito enviar una cadena y recibir una cadena cada vez.

El problema que tengo es que si primero recibo una cadena como hello world , y luego recibo una más corta, la primera es superada por la segunda, en lugar de borrar la primera y escribir la nueva.

Por lo tanto, si primero recibo el hello world , y luego me supposes que tengo que recibir bye , lo que realmente recibe es byelo world .

Entonces, ¿cómo puedo borrar el búfer cada vez que un recibir lo que quiero?

Code Snipets

Enviar datos:

  byte[] send1 = message_full1.getBytes(); GlobalVar.mTransmission.write(send1); 

Escribir llamada:

 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); } 

Escribir Tema:

  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) {} } 

Finalmente, lea el Tema:

  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; } } } 

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.