Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to repeat a coundown timer?

I would like to know if it is possible to repeat a CountDownTimer infinitely?

I would like to make a blind test, which change the song when the timer is out & restart with an other song.

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.jeu);

    int timeinminutes=1;

    new CountDownTimer(timeinminutes*21000, 1000) 
    {

        TextView jeutimer = (TextView) findViewById(R.id.jeu_timer);

         public void onTick(long millisUntilFinished) 
         {
             long scnds=0;
             scnds=(millisUntilFinished/1000);
             jeutimer.setText( "" + scnds);
         }


         public void onFinish() 
         {

         }
  }.start();

My problem is that there's no "restart" function, and I want to restart my countdown infinitely

like image 491
omnisius Avatar asked Mar 12 '13 02:03

omnisius


2 Answers

you can restart it again-

        timer =new CountDownTimer(360000,3000) {

        @Override
        public void onTick(long millisUntilFinished) {

            //Some work

        }

        @Override
        public void onFinish() {
            timer.start(); // start it again after it finishes

        }
    }.start();
like image 120
Aada Avatar answered Oct 06 '22 00:10

Aada


calling "this.start" in the onFinish() method also works just fine

like image 22
Darius Andrei Avatar answered Oct 05 '22 23:10

Darius Andrei