1

I want to set a countdown timer for 30s seconds. After 30 seconds I want it to do (whatever) and then loop and start the 30 second countdown again.

2 Answers2

1
new CountDownTimer(30000, 1000)
    {

        public void onTick(long millisUntilFinished)
        {
            tv_timer.setText("seconds remaining: " + millisUntilFinished / 1000);
        }

        public void onFinish()
        {
            //do your stuff and at end of that stuff again call CountDownTimer method
        }
    }.start();
0

You may try this one.

private final Handler mHandler = new Handler();
private final int delay = 30 * 1000; //30 secs

private void startCountDown(){
   mHandler.postDelayed(task, delay); 
}

private Runnable task = new Runnable() {
    @Override
    public void run() {

        //do something...

        if (true) { //condition to continue...
            mHandler.postDelayed(this, delay);
        }
    }
};
Ocor Kcirad
  • 354
  • 2
  • 4