刚上线的项目就收到了crash 日志
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@2747afb0 is not valid; is your activity running?
重现bug发现是一进去APP就马上退出来就会crash, 检查代码发现是因为进去首页马上退出来Activity就finish掉了,但是对话框却 在 继续弹出,所以就crash了,
DialogHelper.showVerifyDialog(MainActivity.this, String.format("是否定位为当前城市", city), getString(R.string.location_differ_site_cancel), getString(R.string.location_differ_site_switch), new DialogSelectedListener() { @Override public void onConfirm() { super.onConfirm(); } @Override public void onCancel() { super.onCancel(); } });
在网上查了下,很多资料说将Activity.this换成getParent()就可以了,试了发现并不行,
最后在DialogHelper前加上isFinishing的判断就可以了