例外:android.view.WindowManager $ BadTokenException

时间:2018-03-22 07:49:22

标签: android

此次崩溃多次发生,但我不明白究竟是什么问题。

Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@42383ff8 is not valid; is your activity running?
   at android.view.ViewRootImpl.setView(ViewRootImpl.java:536)
   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
   at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2852)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
   at android.app.ActivityThread.access$800(ActivityThread.java:135)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5017)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
   at dalvik.system.NativeStart.main(NativeStart.java)

我在每次打开对话框之前检查一下,如果活动正在结束,但仍然会发生此崩溃。我在Crashlytics中发现了这些崩溃。我无法在我的测试设备中重现。有什么想法吗?

崩溃报告未在builder.show()或dialog.show()中显示崩溃。

private void showIntroText() {
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
            .setMessage(R.string.msg_intro)
            .create();
    if (!isFinishing()) {
        alertDialog.show();
        final Handler handler = new Handler();
        handler.postDelayed(() -> {
            if (!MainActivity.this.isFinishing() && alertDialog.isShowing()) {
                alertDialog.dismiss();
            }
        }, 3000);
    }
}

0 个答案:

没有答案