Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I check if ProgressBar isShowing before dismissing it?

Tags:

android

Im dismissing progress dialog when AsyncTask is finished. Should i check isShowing before dismissing it?

I've tried remove this check and it works normally, but may be there are hidden traps?

if (progressDialog.isShowing()) {
  progressDialog.dismiss();
}
like image 718
Alexey Zakharov Avatar asked Oct 17 '11 10:10

Alexey Zakharov


2 Answers

You shouldnt have to check for isShowing to dismiss it. If you dont check for isShowing it will just ignore the dismiss() is the progressbar isnt showing.

But checking for isShowing is a good practice. So it wont hurt to continue to check for it.

like image 114
coder_For_Life22 Avatar answered Oct 04 '22 19:10

coder_For_Life22


Is seems that is checked inside implementation:

public void dismiss() {
    if (Thread.currentThread() != mUiThread) {
        mHandler.post(mDismissAction);
    } else {
        mDismissAction.run();
    }
}

private void dismissDialog() {
    if (mDecor == null || !mShowing) {
        return;
    }

    try {
        mWindowManager.removeView(mDecor);
    } finally {
        mDecor = null;
        mWindow.closeAllPanels();
        onStop();
        mShowing = false;

        sendDismissMessage();
    }
} 
like image 25
Alexey Zakharov Avatar answered Oct 04 '22 21:10

Alexey Zakharov