Android Progress Dialog not showing
Posted
by
ilomambo
on Stack Overflow
See other posts from Stack Overflow
or by ilomambo
Published on 2012-06-07T15:54:58Z
Indexed on
2012/06/08
16:40 UTC
Read the original article
Hit count: 191
This is the handler, in the main Thread, which shows and dismisses a progress dialog.
public static final int SHOW = 0;
public static final int DISMISS = 1;
public Handler pdHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
Log.i(TAG, "+ handleMessage(msg:" + msg + ")");
switch(msg.what) {
case SHOW:
pd = ProgressDialog.show(LogViewer.this, "", getText(R.string.loading_msg), true);
break;
case DISMISS:
if(pd != null) {
pd.dismiss();
pd = null;
}
break;
}
}
};
The message to show the progress is:
pdHandler.sendMessage(pdHandler.obtainMessage(SHOW));
The message to dismiss it is:
pdHandler.sendMessage(pdHandler.obtainMessage(DISMISS));
It works well when I call it before I start an AsyncTask, the AsyncTask onPostExecute() dismisses it.
But when it runs within a runnable (runOnUiThread), the dialog does not show. Examining the pd variable on the debugger, it shows that is is created, it is running and it is visible, but in practice it is not visible.
Any suggestion?
UPDATE:
I did the obvious test I should have done in the first place. I commented the DISMISS message. And the progress dialog did show up. It appeared too late, after the runnable was finished.
I undestand now that the DISMISS message did dismiss the not-yet-visible ProgressDialog, that's why I did not see it.
The question becomes now: I need the ProgressDialog to show BEFORE the runnable code is executed. And it is not so straight forward. My call hierarchy is like this:
onScrollEventChanged
--> runOnUiThread (
--> checkScrollLimits
--> if need to scroll
show ProgressDialog "Loading"
get new data into table
dismiss ProgressDIalog
)
I tried something like this:
onScrollEventChanged
--> checkScrollLimits
--> if need to scroll
show ProgressDialog "Loading"
--> runOnUiThread (
get new data into table
dismiss ProgressDIalog
)
But still the dismiss message got there before the ProgressDialog could show.
According to Logcat there is a five second interval between the arrival of the SHOW message and the arrival of the DISMISS message.
UPDATE II:
I though I will use the isShowing() method of ProgressDIalog
pd = ProgressDialog.show(...)
while(!pd.isShowing());
But it does not help at all, it returns true even if the dialog is not showing yet.
© Stack Overflow or respective owner