3

I have a fragment with some buttons in it, when a button is clicked it should show a ProgressDialog, load an array of bitmaps and show it in the fragment in a gallery, dismiss ProgressDialog.

But the ProgressDialog doesn't show immediately, it take something like 1 or 2 seconds and it just blink at the moment when my gallery is show.

Im doing this after click:

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

    //load images
    //show gallery

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

My Handler at onCreate:

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

Im using Android 3.1

Logcat shows anything :(

03-09 13:17:32.310: D/DEBUG(5695): before show()
03-09 13:17:32.350: D/DEBUG(5695): after show()
rafael
  • 732
  • 1
  • 11
  • 20
  • post you full code? Are you used Thread or Async for this ? – Samir Mangroliya Mar 09 '12 at 15:19
  • @Samir: He said he creates `Handler` at `onCreate`, and show `ProgressDialog` after click. I see no problem about that code. –  Mar 09 '12 at 15:26
  • @rafael: Could you please filter the logs? For example: `import android.util.Log; ... Log.d("your-tag", "before show()"); progressDialog.show(); Log.d("your-tag", "after show()");`... And filter all logs made by your application only. –  Mar 09 '12 at 16:05
  • @rafael: Thanks a lot. But I could not help you, this is strange :-( –  Mar 09 '12 at 16:23

2 Answers2

1

Documentation does not tell much about setIndeterminate(boolean), so I'm not sure. But I use this in my app, and it works:

ProgressDialog fDialog = new ProgressDialog(your-context);
fDialog.setMessage(your-message);
fDialog.setIndeterminate(true);
// fDialog.setCancelable(cancelable);
fDialog.show();

Could you try it?

  • Same result. I tried to put a Thread.sleep(5000); after load images and the ProgressDialog just started after this, almost at same time of show gallery =( – rafael Mar 09 '12 at 15:42
1

You are loading the images on the main UI thread - you should do this in a background process as it may cause your UI to become unresponsive (and cause your ProgressDialog to show up at the wrong time).

You should look into using an AsyncTask to carry out loading of the images in the background.

Display the ProgressDialog in AsyncTask.onPreExecute, load images in AsyncTask.doInBackground and dismiss the dialog in AsyncTask.onPostExecute.

Che Jami
  • 5,151
  • 2
  • 21
  • 18
  • Thanks, the click event wasn't being consumed until the images load , i moved the load code to inside AsyncTask and it worked – rafael Mar 09 '12 at 18:39