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 Answer 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
Drivers Sea
5783 silver badges12 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Mike087
So, what is the best aproach to accomplish that?
Drivers Sea
Can you expand a little more on what your actual goal is?
Drivers Sea
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.
Explore related questions
See similar questions with these tags.
lang-java