2017-05-03 81 views
0

我有以下的碰撞崩溃驳回的Android

java.lang.IllegalArgumentException: [email protected][] not attached to window manager 
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:473) 
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:382) 
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:128) 
at android.app.Dialog.dismissDialog(Dialog.java:727) 
at android.app.Dialog.-android_app_Dialog-mthref-0(Dialog.java:167) 
at android.app.Dialog$-void__init__android_content_Context_context_int_themeResId_boolean_createContextThemeWrapper_LambdaImpl0.run(Dialog.java) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6688) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 

谁能请帮助,告诉我是什么导致这种崩溃,如何解决呢?

编辑

这是显示对话框

public static void showDialogMessage(Activity activity, String title, 
      String message, String buttonString, final OnClickListener listener) { 

     try { 
       final Dialog dialog = new Dialog(activity); 
       dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
       dialog.setContentView(R.layout.dialog_error_message_layout); 
       dialog.setCancelable(false); 

       TextView titleTV = (TextView) dialog.findViewById(R.id.title_textview); 
       TextView descriptionTV = (TextView) dialog 
         .findViewById(R.id.description_textview); 
       Button okButton = (Button) dialog.findViewById(R.id.ok_button); 
       Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button); 

       titleTV.setText(title); 
       descriptionTV.setText(message); 
       okButton.setText(buttonString); 
       cancelButton.setVisibility(View.GONE); 

       okButton.setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         dialog.dismiss(); 
         if (listener != null) 
          listener.onClick(null); 
        } 
       }); 

       dialog.getWindow().setBackgroundDrawableResource(
         android.R.color.transparent); 
       dialog.show(); 
     } catch (BadTokenException exception) { 
      exception.printStackTrace(); 
     } 
    } 
+0

请张贴一些代码,您显示对话框 –

+0

好的我将编辑帖子 –

回答

1

对话框时成功驳回前Activity被结束发生错误的方法。所以Dialog的观点不附于windowManager

关闭对话框之前添加此检查:

if (!activity.this.isFinishing() && dialog != null) { 
     dialog.dismiss(); 
    } 

另外,您可以在onPause()或活动的onDestroy()解散你的对话框。

@Override 
public void onPause() { 
    super.onPause(); 

    if ((dialog != null) && dialog.isShowing()) 
     dialog.dismiss(); 
    dialog = null; 
}