如何找出造成BadTokenExceptions的原因 [英] How to find out what's causing BadTokenExceptions

查看:83
本文介绍了如何找出造成BadTokenExceptions的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个具有多个活动和服务的Android应用程序.我在导入到项目中的第3方库中定义了一些活动,问题是在某些设备上(尤其是在Samsung Galaxy Tabs中),通过单击背面的一个活动从一个活动切换到上一个活动时,我的应用始终崩溃按钮.

I'm working on an Android application that has multiple activities and services. Some of the activities are defined in 3rd party libraries that I'm importing into my project and the problem is that on some devices (specially in Samsung Galaxy Tabs) my app keeps crashing when switching from one activity to the previous via clicks on the back button.

我做了一个LogCat,发现这是导致崩溃的原因:

I did a LogCat and found this to be the cause of the crashes:

android.view.WindowManager$BadTokenException: Unable to add window -- token
  android.os.BinderProxy@351c808e is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:272)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3017)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

但是有趣的是,我的应用程序的任何类都没有出现在堆栈跟踪中.我在StackOverflow上搜索了类似的问题,但我发现所有其他报告都有BadTokenException的堆栈跟踪,相应的应用程序代码始终出现在堆栈跟踪中.

but the interesting thing is that none of my application's classes appears on the stack trace. I searched for similar problems on StackOverflow but every other report I found that had a stack trace of a BadTokenException, the respective application's code always appeared in the stack trace.

有人知道此问题的常见原因是什么和/或解决该问题的最佳方法吗?我注意到这个问题在三星设备上发生的更多,所以也许这是那些设备上的实际错误.

Does anyone know what are the common causes for this problem and/or the best way to troubleshoot it? I noticed that this problem happens more on Samsung devices so maybe it's an actual bug on those devices.

推荐答案

通常,当您的活动尝试在其 onAttachToWindow()方法被调用(或在其 onDetachFromWindow()方法被调用之后).很有可能是您正在使用的第三方库存在错误,并且不能确保满足此要求.

Usually BadTokenExceptions occur when your activity attempts to create a new Window before its onAttachToWindow() method is called (or after its onDetachFromWindow() method is called). It could very well be that the third party libraries you are using are buggy and do not ensure that this requirement is met.

这篇关于如何找出造成BadTokenExceptions的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆