Search code examples
javaandroidtimercountdowntimer

Waiting for a countdowntimer to finish


I need help with writing a code,

How do I make a code to wait until the countdown timer is finished?

I tried with boolean says if countdown timer is running and in the code, it was like this:

---part 1 of code---

While(running){}

---part2 of the code---

It makes the screen freeze... Idk how to solve this.. help someone?


Solution

  • CountDownTimer already has that, You just need to put the codes that you want to make them work after the timer finished, inside the onFinish(), like below

     countDownTimer = new CountDownTimer(10000, 1000) {
            @Override
            public void onTick(long l) {
    
            }
    
            @Override
            public void onFinish() {
              //this part will work after timer have finished
            }
        }.start();