本文共 846 字,大约阅读时间需要 2 分钟。
关键崩溃的BS如下:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? at android.view.ViewRootImpl.setView(ViewRootImpl.java:579) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) at android.widget.PopupWindow.invokePopup(PopupWindow.java:1315) at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1075) at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1038)
PopupWindow关联的Activity被销毁后,还调用showAtLocation方法
调用showAtLocation方法时,除了调用View的post(Runnable action)(在Runable显示PopupWindow),在调用showAtLocation前需要判断一下关联的Activity是否已经被销毁
//示例代码如下if (!Activity实例.isFinishing()) { PopupWindow实例.showAtLocation(view实现, Gravity.NO_GRAVITY, 0, 0);}
转载地址:http://bxmbi.baihongyu.com/