Friday, 4 January 2013

Simple Timer Example in android



Best Timer example for android



Timer t = new Timer();

  TimerTask task = new TimerTask() {

   @Override
   public void run() {
    runOnUiThread(new Runnable() {

     @Override
     public void run() {
      TextView tv1 = (TextView) findViewById(R.id.timer);
      tv1.setText(time + "");
      if (time > 0)
       time -= 1;
      else
       tv1.setText("Welcome");
     }
    });
   }
  };

  t.scheduleAtFixedRate(task, 0, 1000);