android.view.WindowManager$Badtoken自定义对话框异常
我的应用程序在特定的android版本和设备(VIVO搭载android 5.1和Oneplus搭载android 7.1)上崩溃,并出现以下错误堆栈 QuickMath.java中的代码片段如下android.view.WindowManager$Badtoken自定义对话框异常,android,exception,window-managers,customdialog,Android,Exception,Window Managers,Customdialog,我的应用程序在特定的android版本和设备(VIVO搭载android 5.1和Oneplus搭载android 7.1)上崩溃,并出现以下错误堆栈 QuickMath.java中的代码片段如下 final Dialog customDialog = new Dialog(**this**); customDialog.setContentView(R.layout.custom_dialog_layout); waitTimer.cancel(); // Cancelling the C
final Dialog customDialog = new Dialog(**this**);
customDialog.setContentView(R.layout.custom_dialog_layout);
waitTimer.cancel(); // Cancelling the CountDownTimer before calling the show custom dialog
customDialog.show();
我怀疑customDialog的初始化。我把上下文用作“this”对吗
android.view.WindowManager$BadTokenException:
你应该调用你的活动。这是而不是这是
不要
final Dialog customDialog = new Dialog(this);
Do
final Dialog customDialog = new Dialog(QuickMath.this);
如果您在click listener中显示对话框,那么您需要使用活动。如果没有,它应该可以正常工作。非常感谢@TrickySolutions。有效。请接受我对延迟回复的真诚道歉。我对堆栈溢出还是个新手。我不确定记号在哪里。在做出建议的更改后,同样的问题再次出现在新设备上。有什么需要帮忙的吗?有人能解释一下为什么会这样吗?这个
和类。这个
有什么区别?@AlexanderAgeychenko
final Dialog customDialog = new Dialog(QuickMath.this);