title: Advice on Android Thread
body: <p>Good day and I am here to take some advice from you. Basically I have a class that has two methods as follows. It allows me to send data to the serial port (UART) and I receive data from it. Works fine. </p>
  
  <p>Now, I have to modify it in such a way that it will send some data  to the serial port <strong>serialPort.writeBytes(src.getBytes());</strong> and wait for the reply for 3 seconds, if I get a reply in between 3 seconds it has to be updated to a TextView and if not it has to send the second data  (<strong>serialPort.writeBytes(src1.getBytes());</strong>)and again wait for the reply.</p>
  
  <p>I am not an expert in Threads and Handlers as I have just started to learn it. Please advise me on this. Thank you very much for your time.</p>
  
  <pre><code>public void sendData(){
      final String src = "MYDATA\r";
      final String src1 = "MYDATA1\r";
      serialPort.writeBytes(src.getBytes());
      **// Pause here and wait for the reply**
      serialPort.writeBytes(src1.getBytes());
     **//  Pause here and wait for reply**
  }
  
  
  
  
  private class ReadThread extends Thread {
      byte[] buf = new byte[512];
  
      @Override
      public void run() {
          super.run();
          while (!isInterrupted()) {
              int size;
              if (mInputStream == null)
                  return;
              size = serialPort.readBytes(buf);
  
              if (size &gt; 0) {
  
                  byte[] dest = new byte[size];
                  System.arraycopy(buf, 0, dest, 0, size);
                  byteLinkedList.offer(dest);
                  onDataReceived();
  
              }
          }
      }
  }
  </code></pre>
  
  <p>Now</p>