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:

try{
    progress = ProgressDialog.show(activity, "", "Loading images", true);

    //load images
    //show gallery

}catch(){
    //...
}finally{
    handler.sendEmptyMessage(0);
}

      

My handler in onCreate:

handler = new Handler() {
    public void handleMessage(Message msg) {
         progress.dismiss();
    }
};

      

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()

      

+3


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

.

+1


source


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.setMessage(your-message);
fDialog.setIndeterminate(true);
// fDialog.setCancelable(cancelable);
fDialog.show();

      



Could you try?

+1


source







All Articles