android.view.WindowManager $ BadTokenException:无法添加窗口-令牌android.os.BinderProxy@b0baaa1无效;您的活动正在进行吗? [英] android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@b0baaa1 is not valid; is your activity running?

查看:64
本文介绍了android.view.WindowManager $ BadTokenException:无法添加窗口-令牌android.os.BinderProxy@b0baaa1无效;您的活动正在进行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我在android 7.1.1中总是收到一个错误,显示土司崩溃.很奇怪,有人遇到同样的问题吗?

In recently, i always receive an error in android 7.1.1 that shows toast case crash. It's very strange, is anyone have the same problem?

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@b0baaa1 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:812)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:351)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at android.widget.Toast$TN.handleShow(Toast.java:489)
at android.widget.Toast$TN$2.handleMessage(Toast.java:360)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6475)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1134)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)

推荐答案

当在Toast中显示的Activity上下文不再位于前台时,将发生错误.一种解决方案是仅通过检查活动是否仍处于活动状态而不处于结束状态来显示Toast.这可能并不总是最好的解决方案,因为在某些情况下,Toast可能以异步方式显示(例如在异步任务中),并且一旦Activity不再处于活动状态就显示Toast,这将导致崩溃.

The error happens when a Toast is shown with a context of an Activity that is no longer in the foreground. A solution is to show the Toast only by checking before if the activity is still active and not in a finishing state. This may not be always the best solution as there are scenarios where a Toast may be shown in a asynchronous way, such as within an asynchronous task, and appear once the Activity is no longer active, which will produce the crash.

下一个库说明了当Android中引入该问题时崩溃的原因,并通过捕获错误来解决该问题:

The next library has an explanation of why it crashes, when the issue was introduced in Android, and solves the problem by catching the error:

https://github.com/drakeet/ToastCompat

这篇关于android.view.WindowManager $ BadTokenException:无法添加窗口-令牌android.os.BinderProxy@b0baaa1无效;您的活动正在进行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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