PostDelayed() inside onFinish() in CountDownTimer

42 Views Asked by At

I need to use postDelayed() method inside onFinish() method of the CountDownTimer. I use the following code:

...
public void onFinish() {
  Handler handler = new Handler();
  handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //do something here after 3 seconds
            }
        }, 3000);
}

But it does not work. It does not delay.

1

There are 1 best solutions below

3
Drivers Sea On

It's not going to work. You will have to find another way to accomplish your goal. The reason why, is because your post delayed is ran on a different thread then the onFinish. onFinish will run on the UI tread. After onFinish is ran the class will be closed out and the postDelayed thread will be no more.