Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 = ProgressDialog.show(this, "", "Detecting...",
            true);
    dialog.show();

    dialog.dismiss();

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

like image 993
Sapp Avatar asked Nov 17 '10 21:11

Sapp


People also ask

What can I use instead of progress dialog?

"Deprecated" refers to functions or elements that are in the process of being replaced by newer ones. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar , which can be embedded in your app's UI.

What is meant by ProgressBar describe with example?

We can display the android progress bar dialog box to display the status of work being done e.g. downloading file, analyzing status of work etc. In this example, we are displaying the progress dialog for dummy file download operation. Here we are using android. app. ProgressDialog class to show the progress bar.

How do you set progress dialog in Kotlin?

Step by Step Implementation We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project. Navigate to the app > res > layout > activity_main. xml and add the below code to that file. Below is the code for the activity_main.


1 Answers

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
like image 89
Peter Knego Avatar answered Oct 04 '22 18:10

Peter Knego