title: android Thread handler message passing
body: <p>I found this code on the net. I am a newbie so i don't know much about java and android handler. I know how to use <code>Runnables</code> in handler to post on ui thread. But In this code use of <code>handler.sendMessage(handler.obtainMessage)</code>I didn't get it. I also confused about difference between <code>atomic boolean</code> and <code>boolean</code>. So please exaplain this. help is appreciated.</p>
  
  <pre><code>package com.example.watch;
  import java.util.Calendar;
  import java.util.concurrent.atomic.AtomicBoolean;
  
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Message;
  import android.widget.TextView;
  import android.app.Activity;
  
  public class MainActivity extends Activity {
  
      TextView watch;
      AtomicBoolean ContinueThread = new AtomicBoolean(false);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          watch = (TextView) findViewById(R.id.txtWatch);
          displayCurrentTime();
      }
  
      public void displayCurrentTime() {
  
          Calendar c = Calendar.getInstance();
          // String curTime = String.valueOf(c.getTime());
          int hours = c.get(Calendar.HOUR);
          int minutes = c.get(Calendar.MINUTE);
          int seconds = c.get(Calendar.SECOND);
          String curTime = hours + ":" + minutes + ":" + seconds;
          watch.setText(curTime);
      }
  
      public void onStart() {
          super.onStart();
          Thread background = new Thread(new Runnable() {
  
              @Override
              public void run() {
                  try {
                      while(ContinueThread.get()) {
                          Thread.sleep(1000);
                          handler.sendMessage(handler.obtainMessage());
                      }
                  } catch (Throwable t) {
  
                  }
  
              }
  
          });
          ContinueThread.set(true);
          background.start();
      }
      Handler handler = new Handler() {
          @Override
          public void handleMessage(Message msg) {
              displayCurrentTime();
          }
      };
      public void onStop() {
          super.onStop();
          ContinueThread.set(false);
      }
  
  }
  </code></pre>