title: How to pause / sleep thread or process in Android?
body: <p>I want to make a pause between two lines of code, Let me explain a bit: </p>
  
  <p>-> the user clicks a button (a card in fact) and I show it by changing the background of this button: </p>
  
  <pre><code>thisbutton.setBackgroundResource(R.drawable.icon);
  </code></pre>
  
  <p>-> after let's say 1 second, I need to go back to the previous state of the button by changing back its background: </p>
  
  <pre><code>thisbutton.setBackgroundResource(R.drawable.defaultcard);
  </code></pre>
  
  <p>-> I've tried to pause the thread between these two lines of code with:</p>
  
  <pre><code>try {
      Thread.sleep(1000);
  } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  </code></pre>
  
  <p>However, this does not work. Maybe it's the process and not the Thread that I need to pause?</p>
  
  <p>I've also tried (but it doesn't work):</p>
  
  <pre><code>new Reminder(5);
  </code></pre>
  
  <p>With this:</p>
  
  <pre><code>public class Reminder {
  
  Timer timer;
  
          public Reminder(int seconds) {
              timer = new Timer();
              timer.schedule(new RemindTask(), seconds*1000);
          }
  
          class RemindTask extends TimerTask {
              public void run() {
                  System.out.format("Time's up!%n");
                  timer.cancel(); //Terminate the timer thread
              }
          }  
      }
  </code></pre>
  
  <p>How can I pause/sleep the thread or process?</p>