0

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.

asked Aug 28, 2021 at 21:08

1 Answer 1

1

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.

answered Aug 28, 2021 at 21:14
Sign up to request clarification or add additional context in comments.

3 Comments

So, what is the best aproach to accomplish that?
Can you expand a little more on what your actual goal is?
perhaps you can make a custom finish method. Then when you try to finish the class, call your customer finish method that calls finish internally after the 3 second thread is done.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.