Add a delay to Progress Dialog
The correct way - it does not block your main thread, so UI stays responsive:
dialog.show();Handler handler = new Handler();handler.postDelayed(new Runnable() { public void run() { dialog.dismiss(); }}, 3000); // 3000 milliseconds delay
progress.setProgress(100); Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { pdialog.dismiss(); }}, 3000);
You can also use CountDownTimer
of Android which is much more efficient than any other solution posted and it also support fires on regular interval through its onTick()
method.
Have a look at this example,
new CountDownTimer(3000, 1000) { public void onTick(long millisUntilFinished) { // You don't need anything here } public void onFinish() { dialog.dismiss(); } }.start();