title: android Handler to wait for message for a period of time
body: <p>I have a scenario where a thread waits for a message with Looper.Prepare() and Looper.loop(). When a button clicked in UI, sending a message to Handler notifying the click of button. If no button clicked for 2 minutes, I want to break the looper, how to achieve it ? I tried using Timer and timertask but nothing happens</p>
  
  <p>The code is as follows in the non-ui Thread</p>
  
  <pre><code>   Looper.prepare();
        uiHandler = new Handler() {
        public void handleMessage(Message msg) {
        // Act on the message
          if (msg.obj.contains("DONE")) {
          Toast.makeText(MainActivity.this, "Done task",                   
                   Toast.LENGTH_LONG).show();
           }     
        }
       }
    Looper.loop();
  </code></pre>
  
  <p>From UI thread :</p>
  
  <pre><code> btnDone.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Message msg = Message.obtain();
              msg.obj = "DONE";
              uiHandler.sendMessage(msg);
          }
      });
  </code></pre>