1.android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?,exceptionmsg:android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
崩溃可能是因为activity还未创建或者穿的context不是activity context
2.java.lang.IllegalArgumentException: View=DecorView@e97db5b[] not attached to window manager,exceptionmsg:java.lang.IllegalArgumentException: View=DecorView@e97db5b[] not attached to window manager
崩溃原因是:dialog调用dismiss方法时,activity isFinishing或者isDestroyed,使得dialog无法获取activity对应的window manager进而抛出异常
本文探讨了Android中常见的BadTokenException和IllegalArgumentException的成因,包括Activity未创建或使用错误的Context,以及Dialog在Activity销毁时的适配问题。通过实例分析,提供了解决这些问题的方法和预防措施。
1万+

被折叠的 条评论
为什么被折叠?



