Sapp Sapp - 1 year ago 282
Android Question

Add a delay to Progress Dialog

I want to make a dummy progress dialog appear for 2 or 3 seconds. It won't actually do anything other than say detecting. I have the code:

ProgressDialog dialog =, "", "Detecting...",


But what do I put in between the show, and the dismissal to have the dialog appear for a few seconds? Thanks!

Answer Source

The correct way - it does not block your main thread, so UI stays responsive:;

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {
}, 3000); // 3000 milliseconds delay
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download