Heller Velasquez
Heller Velasquez

Reputation: 1

Prevent this from happening with the ountdown timer function

I have this code in android studio:

The question is that if I give the button back and the main activity takes me, that is going to continue executing.

How do I make it so that once it's behind, it does not run what's in the onfinished?

new CountDownTimer (40000,1000) { @Override public void onTick(long l) { crono.setText("00:"+l/1000); if(contador==10) {

            }
        }

        @Override
        public void onFinish()
        {
            if(value.equals("tiempo"))
            {
                crono.setText("00:00");
            }
            else
            {
            esperar();
            }

        }
    }.start();

Upvotes: 0

Views: 44

Answers (1)

Ankit ihelper Sharma
Ankit ihelper Sharma

Reputation: 470

CountDownTimer class help us to implement timer with custom time interval and duration. It provide 2 callback onTick(int millisUntilFinished) which called after each interval and onFinish is called when time duration is completed.

If you want to stop countdown then store instance countdown and call countdown.cancel() in onDestroy or button click(any where by user action)

You can refer this

Upvotes: 0

Related Questions