Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is the ProgressDialog not being dismissed, in this case?
    text
    copied!<p>There are a number of questions involving the lack of ability to dismiss a ProgressDialog, but none of them seem to cover my situation.</p> <p>I have a Thread that runs a Runnable object that, when it completes, sends a message to a Handler object which I'm certain is sitting on the same thread as the ProgressDialog. The handler does this:</p> <pre><code>if(progressDialog != null){ Log.w(TAG, "Progress dialog is dismissed"); progressDialog.dismiss(); }else{ Log.w(TAG, "Progress dialog is null"); } </code></pre> <p>I've done this a million times before, and it's worked. The ProgressDialog goes away. But, in one particular instance, it doesn't.</p> <p>In this particular case, a ProgressDialog (we'll call uploadChangesDialog) is showing, then a particular Handler (uploadChangesHandler) is called. After dismissing the uploadChangesDialog, it does a check that, if true, starts a different ProgressDialog (refreshViewDialog) and a Runnable (refreshViewRunnable) in a Thread. However, when it's Handler is called (refreshViewHandler), it can't close the dialog. But it <em>does</em> log <code>Progress dialog is dismissed</code>.</p> <p>This is particularly strange, because the refreshViewsRunnable is run when the Activity is started, too, but it can get rid of the dialog then, just fine. The progressDialog variable above is the only one of it's kind, which is supposed to hold whatever ProgressDialog is currently showing.</p> <p>I've done this with AlertDialogs before, but they know how to close themselves, so if I'm doing something wrong, then I wouldn't have noticed.</p> <p>In the onCreateDialog() method:</p> <pre><code>case DIALOG_REFRESH_VIEW: progressDialog = new ProgressDialog(this); progressDialog.setMessage("Loading details..."); progressDialog.setCancelable(false); return progressDialog; </code></pre> <p>Copied for each instance, with a different message. I did change it to all dialogs pointing to the same code, and setting the message in onPrepareDialog(), but that didn't change any behaviour.</p> <p>In the UploadChangesRunnable:</p> <pre><code>public void run(){ int result = 0; if(uploadChanges()){ result = 1; } uploadChangesHandler.sendEmptyMessage(result); } </code></pre> <p>And then in uploadChangesHandler:</p> <pre><code>public void handleMessage(Message msg){ if(progressDialog != null){ progressDialog.dismiss(); } if(msg.what == 0){ showDialog(DIALOG_UPLOAD_CHANGES_FAILED); //This is an AlertDialog }else{ //All this does is showDialog(DIALOG_REFRESH_VIEW) then run the thread. //This method is in the enclosing Activity class. refreshViewInThread(); } } </code></pre> <p>Finally, the refreshViewInThread method:</p> <pre><code>private void refreshViewInThread(){ showDialog(DIALOG_REFRESH_VIEW); Thread thread = new Thread(new RefreshViewRunnable(refreshViewHandler)); thread.start(); } </code></pre> <p>And the RefreshViewRunnable looks remarkably similar to the UploadChangesRunnable.</p> <p>There must be some special case that makes me lose the link to my progressDialog, and the dialog that I'm dismissing is likely not the dialog that is showing, but I can't think of how that could be. Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload