无法添加窗口 - 令牌android.os.BinderProxy无效;你的活动是否运行? [英] Unable to add window -- token android.os.BinderProxy is not valid; is your activity running?

查看:105
本文介绍了无法添加窗口 - 令牌android.os.BinderProxy无效;你的活动是否运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过Facebook API连接到Facebook,我按照这个例子:

  public void onAuthSucceed(){
mText.setText(你已经登录!);
//这是调用帖子消息对话框的代码。
mFacebook.dialog(Example.this,feed,new SampleDialogListener());
}

我在logcat中收到此错误:

  03-02 13:32:08.629:E / AndroidRuntime(14991):android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌android.os .BinderProxy @ 405180f8无效;你的活动是否运行? 
03-02 13:32:08.629:E / AndroidRuntime(14991):在android.view.ViewRoot.setView(ViewRoot.java:532)
03-02 13:32:08.629:E / AndroidRuntime(14991):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
03-02 13:32:08.629:E / AndroidRuntime(14991):在android.view.WindowManagerImpl.addView(WindowManagerImpl .java:91)
03-02 13:32:08.629:E / AndroidRuntime(14991):在android.view.Window $ LocalWindowManager.addView(Window.java:424)
03-02 13 :32:08.629:E / AndroidRuntime(14991):在android.app.Dialog.show(Dialog.java:241)
03-02 13:32:08.629:E / AndroidRuntime(14991):at com。 facebook.android.Facebook.dialog(Facebook.java:780)
03-02 13:32:08.629:E / AndroidRuntime(14991):在com.facebook.android.Facebook.dialog(Facebook.java:737 )
03-02 13:32:08.629:E / AndroidRuntime(14991):在com.facebook.android.Example $ SampleAuthListener.onAuthSucceed(Example.java:113)
03-02 13:32 :08.629:E / AndroidRuntime(14991):在com.facebook.andr oid.SessionEvents.onLoginSuccess(SessionEvents.java:78)
03-02 13:32:08.629:E / AndroidRuntime(14991):在com.facebook.android.Example $ LoginDialogListener.onComplete(Example.java:88 )
03-02 13:32:08.629:E / AndroidRuntime(14991):at com.facebook.android.Facebook $ 1.onComplete(Facebook.java:320)
03-02 13:32: 08.629:E / AndroidRuntime(14991):at com.facebook.android.FbDialog $ FbWebViewClient.shouldOverrideUrlLoading(FbDialog.java:144)
03-02 13:32:08.629:E / AndroidRuntime(14991):在android .webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:218)
03-02 13:32:08.629:E / AndroidRuntime(14991):在android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:337)
03-02 13:32:08.629:E / AndroidRuntime(14991):android.os.Handler.dispatchMessage(Handler.java:99)
03-02 13:32:08.629:E / AndroidRuntime 14991):在android.os.Looper.loop(Looper.java:130)
03-02 13:32:08.629:E / AndroidRuntime(14991):在android.app.ActivityThread.main(Ac tivityThread.java:3687)
03-02 13:32:08.629:E / AndroidRuntime(14991):java.lang.reflect.Method.invokeNative(Native Method)
03-02 13:32 :08.629:E / AndroidRuntime(14991):在java.lang.reflect.Method.invoke(Method.java:507)
03-02 13:32:08.629:E / AndroidRuntime(14991):at com。 android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)
03-02 13:32:08.629:E / AndroidRuntime(14991):at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:625)
03-02 13:32:08.629:E / AndroidRuntime(14991):at dalvik.system.NativeStart.main(Native Method)
任何想法?

当您显示不再存在的上下文的对话框时,可能会发生这种情况。一个常见的情况 - 如果显示对话框操作是在异步操作之后,并且在该操作期间,原始活动(即对话框的父对象)将被销毁。有一个很好的描述,请看这篇博文和评论:



http://dimitar.me/android-displaying-dialogs-from-background-threads/



从堆栈跟踪在上面,看起来,图书馆图书馆异步地转移了auth操作,你有一个Handler - 回调机制(在监听器上调用onComplete),可以轻松地创建这种场景。



当我看到这在我的应用程序中报告时,它很少见,并且与博客文章中的经验相匹配。在AsyncTask的工作中,这个活动出现了错误。我不知道你的修改如何可以导致每次,但也许你引用一个Activity作为对话框的上下文,总是在您的代码执行时被销毁?



此外,虽然我不确定这是否是最佳方式来判断您的活动是否正在运行,但请参阅此回答以获取一种方法:



检查活动是否活动


I try to connect to Facebook throught Facebook API, I follow this example: https://github.com/facebook/facebook-android-sdk/tree/master/examples/simple

Everything is ok, but when I try to edit some code, I mean I want to display the dialog post message after the login is successful like this:

public void onAuthSucceed() {
        mText.setText("You have logged in! ");   
        //This is the code to call the post message dialog.                     
        mFacebook.dialog(Example.this, "feed",new SampleDialogListener());   
    }

I receive this error in the logcat:

03-02 13:32:08.629: E/AndroidRuntime(14991): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@405180f8 is not valid; is your activity running?
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.view.ViewRoot.setView(ViewRoot.java:532)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.view.Window$LocalWindowManager.addView(Window.java:424)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.app.Dialog.show(Dialog.java:241)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.facebook.android.Facebook.dialog(Facebook.java:780)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.facebook.android.Facebook.dialog(Facebook.java:737)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.facebook.android.Example$SampleAuthListener.onAuthSucceed(Example.java:113)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.facebook.android.SessionEvents.onLoginSuccess(SessionEvents.java:78)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.facebook.android.Example$LoginDialogListener.onComplete(Example.java:88)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.facebook.android.Facebook$1.onComplete(Facebook.java:320)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.facebook.android.FbDialog$FbWebViewClient.shouldOverrideUrlLoading(FbDialog.java:144)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:218)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:337)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.os.Looper.loop(Looper.java:130)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at android.app.ActivityThread.main(ActivityThread.java:3687)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at java.lang.reflect.Method.invokeNative(Native Method)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at java.lang.reflect.Method.invoke(Method.java:507)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-02 13:32:08.629: E/AndroidRuntime(14991):    at dalvik.system.NativeStart.main(Native Method)

Any idea?

解决方案

This can occur when you are showing the dialog for a context that no longer exists. A common case - if the 'show dialog' operation is after an asynchronous operation, and during that operation the original activity (that is to be the parent of your dialog) is destroyed. For a good description, see this blog post and comments:

http://dimitar.me/android-displaying-dialogs-from-background-threads/

From the stack trace above, it appears that the facebook library spins off the auth operation asynchronously, and you have a Handler - Callback mechanism (onComplete called on a listener) that could easily create this scenario.

When I've seen this reported in my app, its pretty rare and matches the experience in the blog post. Something went wrong for the activity/it was destroyed during the work of the the AsyncTask. I don't know how your modification could result in this every time, but perhaps you are referencing an Activity as the context for the dialog that is always destroyed by the time your code executes?

Also, while I'm not sure if this is the best way to tell if your activity is running, see this answer for one method of doing so:

Check whether activity is active

这篇关于无法添加窗口 - 令牌android.os.BinderProxy无效;你的活动是否运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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