title: Update android Textview continuously
body: <p>I am working on an Android Application which have an one <code>activity</code> class and <code>service</code> class. In <code>service</code>, Continuous bulk <code>data (1090 bytes)</code> will be received every 10 milliseconds. I need to update the <code>text view</code> continuously with these bulk data. What is recommended way to update <code>Text view</code> from a continuous background service?</p>
  
  <p>Service Class</p>
  
  <pre><code>public class RecepService extends Service {
  
  public static Handler mHandler;
  StringBuilder hexstring;
  
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  @Override
  public void onCreate() {
      super.onCreate();
  
      init();
  }
  
  private void init() {
  
      mHandler = new Handler() {
          @Override
          public void handleMessage(Message msg) {
              if (msg.what == 0x123) {
  
                  byte[] readBuf = (byte[]) msg.obj;
                  int readBuflen = msg.arg1;
  
                  // here will receive 1090 bytes of data 
                  // every 10 milliseconds
                  Receivepatientattributes(readBuf,readBuflen);
              }
          }
      };
  }
  
  public void Receivepatientattributes(byte[] readBuf, int len) {
  
      String total_data = "";
      total_data = bytetohex(readBuf, len);
      MainActivity.recep.setText(MainActivity.recep.getText().toString() + "\t" +
              "" + total_data );
  }
  
  String bytetohex(byte[] txt, int len) {
  
      String p="";
      byte[] text = new byte[len];
      text = txt;
  
      hexstring = new StringBuilder();
      for (int j = 0; j &lt; len; j++) {
  
          String hex= Integer.toHexString(0xFF &amp; txt[j]);
  
          if (hex.length()==1) {
              hexstring.append("0");
          }
  
          hexstring.append(hex+" ");
  
      }
  
      p=p+hexstring.toString();
      return p;
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
      return START_STICKY;
  }
  }
  </code></pre>