IllegalArgumentException in ProgressDialog.dismiss

I got this crash report:

java.lang.IllegalArgumentException: View not attached to window manager at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:395) at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:239) at android.view.Window$LocalWindowManager.removeView(Window.java:441) at android.app.Dialog.dismissDialog(Dialog.java:306) at android.app.Dialog.access$000(Dialog.java:89) at android.app.Dialog$1.run(Dialog.java:132) at android.app.Dialog.dismiss(Dialog.java:296) at ZhuangDictActivity$1.onPageFinished(ZhuangDictActivity.java:311) at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:299) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:150) at android.app.ActivityThread.main(ActivityThread.java:4385) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607) at dalvik.system.NativeStart.main(Native Method) 

Line 311 in ZhuangDictActivity is searchProgressDialog.dismiss () below:

 public void onPageFinished(WebView view, String url) { searchProgressDialog.dismiss(); onConfigurationChanged(ZhuangDictActivity.this.getResources().getConfiguration()); super.onPageFinished(view, url); } 

This is ProgressDialog.show:

 public void onPageStarted(WebView view, String url, Bitmap favicon) { searchProgressDialog.setMessage("Loading"); searchProgressDialog.show(); super.onPageStarted(view, url, favicon); } 

A crash occurred when the orientation was changed before the WebView was loaded.

+8
android
source share
5 answers

You simply quit, and do not check whether it is shown or not. First you need to check this:

 if (searchProgressDialog != null && searchProgressDialog.isShowing()) { searchProgressDialog.dismiss(); } 
+29
source share

Please override the onDestroy method.

 @Override protected void onDestroy() { super.onDestroy(); if((progressDialog != null) && progressDialog.isShowing() ){ progressDialog.dismiss(); } } 
+4
source share

This is because you are trying to show a dialogue of progress, but at this moment your activity seems to be destroyed ...

+1
source share
  if (mProgressDialog != null) { mProgressDialog.dismiss(); mProgressDialog = null; } 
0
source share

I think that you have already rejected the dialog through the code, and you do it again. Therefore, please check if the dialog object is null or not before rejecting it. And set it to null.

0
source share

All Articles