我正在使用来自onClick回调的AlertDialog.Builder为按钮创建一个警告对话框
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setCancelable(false);
builder.setNegativeButton(R.string.cancel, (dialog, which) -> isReporting = false);
builder.show();
99.9%的时间一切正常,但最近我开始看到一些像这样的崩溃报告:
Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- window android.view.ViewRootImpl$W@db362a2 has already been added
at android.view.ViewRootImpl.setView(ViewRootImpl.java:902)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:97)
at android.app.Dialog.show(Dialog.java:538)
at android.support.v7.app.AlertDialog$Builder.show(AlertDialog.java:958)
at com.gurushots.app.adapters.VoteAdapter.showReporting(VoteAdapter.java:242)
at com.gurushots.app.adapters.VoteAdapter.lambda$onBindViewHolder$2$VoteAdapter(VoteAdapter.java:197)
at com.gurushots.app.adapters.VoteAdapter$$Lambda$2.onClick(Unknown Source)
at android.view.View.performClick(View.java:6213)
at android.view.View$PerformClick.run(View.java:23645)
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:6642)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
异常表示我正在尝试重新添加已经显示的警报,但事实并非如此。 为什么会这样?