user1178492
user1178492

Reputation: 51

Android Progress Dialog not showing until the function finish running (AsyncTask)

When a button is clicked I'm calling the async class in a function and I need to show progressDialog until it runs the displaylist function. But it shows up only after the function finished running and closes immediately. Please help me what am I doing wrong here.

public class FilterAsyncTask extends AsyncTask<Void, Void, Void> {

    ProgressDialog dispProgress;

     @Override
        protected void onPreExecute()
        {
            dispProgress = ProgressDialog.show(Filter.this, "Please wait...",
                    "Loading...", true, true);
        }

       protected Void doInBackground(Void... params) {

           return null;
       }

       protected void onPostExecute(Void result) {
          super.onPostExecute(result);

        MerchantsActivity.displayList();
            dispProgress.cancel();
            finish();
       }

    }

Upvotes: 0

Views: 489

Answers (2)

Reuben Scratton
Reuben Scratton

Reputation: 38707

Your AsyncTask will complete immediately because you do exactly nothing in doInBackground()! That's where your long-running background non-UI code is supposed to go...

Upvotes: 1

Boris Strandjev
Boris Strandjev

Reputation: 46943

I would recommend you not to use the static ProgressDialog#show method. Rather donew ProgressDialog() and initialize it accordingly and finally call show(). I have never used the static method and do not know how it works, but I have used the other option. Furthermore the static method seems to have no available documentation.

Upvotes: 0

Related Questions