Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put an app main thread to sleep, to show progress dialog changes?

I have an app and want to put the main thread to sleep for 1500ms, so I can show a ProgressDialog, but I don't know how to do it. It's possible to stop an app main thread? I can achieve the same goal using another thread right?

like image 737
pharaoh Avatar asked Dec 08 '25 12:12

pharaoh


2 Answers

Stopping the main thread is usually a bad idea as it would also stop all UI interaction processing.

Try making the progress dialog modal. This will prevent the user from doing anything on your UI until the dialog is gone. I think this will achieve what you want to do and is compatible with how Android works

like image 148
Carsten Avatar answered Dec 10 '25 01:12

Carsten


not a good idea to do this, but if you have to use this

try {
    Thread.sleep(1500);
} catch (InterruptedException e) {
    //handle
}
like image 28
Eshaan Avatar answered Dec 10 '25 00:12

Eshaan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!