1

Here is the simple code:

if (myProgressDialog.isShowing()) {
    myProgressDialog.dismiss();
}

Could anyone shed some light on why myProgressDialog.dismiss() sometimes causes the following exception:

java.lang.IllegalArgumentException: View=com.android.internal.policy.PhoneWindow$DecorView{83559f5 V.E...... R......D 0,0-1026,348} not attached to window manager
Stack trace: java.lang.IllegalArgumentException: View=com.android.internal.policy.PhoneWindow$DecorView{83559f5 V.E...... R......D 0,0-1026,348} not attached to window manager
        at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:424)
        at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:350)
        at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
        at android.app.Dialog.dismissDialog(Dialog.java:362)
        at android.app.Dialog.dismiss(Dialog.java:345)
Hong
  • 17,643
  • 21
  • 81
  • 142
  • 1
    IllegalArgumentException: "View=com.android.internal.policy.PhoneWindow$DecorView{83559f5 V.E...... R......D 0,0-1026,348} not attached to window manager". Error saying your dialog no longer attached to your current fragment/activity. check your fragment/activity is still visible before your dialog is close. – james Sep 27 '17 at 01:34
  • Thank you for the tip. It is occasionally reported in the log from users. I cannot reproduce this. I have just added code to check the activity. – Hong Sep 27 '17 at 14:45

2 Answers2

3

Try this fixed code:

 if (YourActivity.this.isDestroyed()) { // or call isFinishing() if min sdk version < 17
    return;
 } 
 if (myProgressDialog != null && myProgressDialog.isShowing()) {
    myProgressDialog.dismiss();
 }

ref : https://stackoverflow.com/a/23586127/6759520

amuyu
  • 236
  • 1
  • 2
  • 9
2

This is because your activity is destroyed. check if you have called finish() in your class before calling progress dialog.. Thanks