第一种情况
分析:
当打开Dialog或者PopupWindow时,所依附的View不存在或是token令牌不存在,简单来说就是所在的窗体(Activity)已关闭
出现时机:
在Activity 中开定时打开Dialog,然后关闭Activity;
解决方法:
在打开Dialog或者PopupWindow,首先检测Activity是否已关闭
/**
* 检查Activity是否已关闭
*/
public static Boolean checkActivityIsRun(Activity activity) {
if (activity == null) {
return false;
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
return !activity.isFinishing() || !activity.isDestroyed();
}
return !activity.isFinishing();
}
错误日志
java.lang.RuntimeException: Unable to start receiver com.xxx.JpushReceiver: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@83caed is not valid; is your activity running?
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3398)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1743)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6816)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1455)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@83caed is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:922)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:105)
at android.app.Dialog.show(Dialog.java:404)
at com.cloudy.linglingbang.activity.msg.a.c.a(ReceiverMsgLab.java:72)
at com.xxx.JpushReceiver.onReceive(JpushReceiver.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3391)
... 8 more
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@83caed is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:922)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:105)
at android.app.Dialog.show(Dialog.java:404)
at com.cloudy.linglingbang.activity.msg.a.c.a(ReceiverMsgLab.java:72)
at com.cloudy.linglingbang.app.receiver.JpushReceiver.onReceive(JpushReceiver.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3391)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1743)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6816)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1455)
第二种情况
Toast 造成的
Android7-1-Toast之坑
网友评论