ProgressDialog doesn't appear immediately

I have a fragment with multiple buttons in it, when the button is clicked, it should show the ProgressDialog, load the bitmap array and show it in the fragment in the gallery, release the ProgressDialog.

But the ProgressDialog doesn't show up right away, it takes something like 1 or 2 seconds, and it just blinks the moment my gallery is shown.

I do this after click:

    progress =, "", "Loading images", true);

    //load images
    //show gallery



My handler in onCreate:

handler = new Handler() {
    public void handleMessage(Message msg) {


Im using Android 3.1

Logcat shows everything :(

03-09 13:17:32.310: D/DEBUG(5695): before show()
03-09 13:17:32.350: D/DEBUG(5695): after show()



source to share

2 answers

You are loading images on the main UI thread - you have to do this in the background, as this can cause your UI to stop responding (and cause it to appear ProgressDialog

at the wrong time).

You have to learn AsyncTask in order to download images in the background.

Display ProgressDialog

to AsyncTask.onPreExecute

upload images AsyncTask.doInBackground

and release the dialogue AsyncTask.onPostExecute




The documentation says little about setIndeterminate (boolean) , so I'm not sure. But I am using this in my application and it works:

ProgressDialog fDialog = new ProgressDialog(your-context);
// fDialog.setCancelable(cancelable);;


Could you try?



All Articles