当我试图从Facebook SDK显示墙上发布对话框时,我得到了一个Bad Token Exception(它每2次运行应用程序就会发生).
我有一个"发布"按钮,如果用户登录到他的FB帐户,则显示对话框,或者显示登录对话框(如果用户不是,则显示"在墙上发布"对话框)登录到他的帐户.
这是发布按钮的点击监听器 -
mPostButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if(mLoginButton.getVisibility() == 0) postOnWall(); else mLoginButton.performClick(); } });
这是onAuthSucceed()监听器 -
public void onAuthSucceed() { postOnWall(); }
这是PostOnWall函数(显示发布对话框) -
public void postOnWall() { Bundle params = new Bundle(); params.putString("name", FBname); params.putString("link", FBlink); params.putString("description", FBdescription); params.putString("picture", FBpicture); con = this; mFacebook.dialog(con, "feed", params, new SampleDialogListener()); }
这是错误的日志 -
05-05 16:25:09.601: WARN/WindowManager(109): Attempted to add application window with unknown token HistoryRecord{405416b0 android.alco/.do_drive}. Aborting. 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@405db9f8 is not valid; is your activity running? 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.view.ViewRoot.setView(ViewRoot.java:527) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.view.Window$LocalWindowManager.addView(Window.java:424) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.app.Dialog.show(Dialog.java:241) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at com.facebook.android.Facebook.dialog(Facebook.java:622) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.alco.do_drive.postOnWall(do_drive.java:258) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.alco.do_drive$SampleAuthListener.onAuthSucceed(do_drive.java:172) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.alco.SessionEvents.onLoginSuccess(SessionEvents.java:78) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at android.alco.LoginButton$LoginDialogListener.onComplete(LoginButton.java:100) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at com.facebook.android.Facebook$1.onComplete(Facebook.java:308) 05-05 16:25:27.292: ERROR/AndroidRuntime(20089): at com.facebook.android.FbDialog$FbWebViewClient.shouldOverrideUrlLoading(FbDialog.java:133)
我看了一遍,我找不到解决方案.
编辑 - 仅当用户未登录时才会发生这种情况.在这种情况下,他按下"发布"按钮,登录,然后调用"postOnWall"函数,这会生成错误.我现在正在研究它2天,但却找不到任何相关信息.
谢谢!
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) { Log.d("Facebook-WebView", "Webview loading URL: " + url); super.onPageStarted(view, url, favicon); if(FbDialog.this.isShowing()) mSpinner.show(); }