Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'BadTokenException: Unable to add window' when trying to show Facebook dialog - Android

I'm getting a Bad Token Exception when trying to show the publish on wall dialog from the Facebook SDK(It happens every 2 times I run the app).

I have a 'publish' button, and its job is to show the dialog if the user is logged in to his FB account, or show the login dialog(and then immediately show the 'post on wall' dialog) if the user isn't logged in to his account.

Here's the on click listener of the Publish button -

    mPostButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if(mLoginButton.getVisibility() == 0)
                postOnWall();
            else
                mLoginButton.performClick();
        }
    });  

Here's the onAuthSucceed() listener -

public void onAuthSucceed() {
    postOnWall();
}

Here's the PostOnWall function(which shows the publish dialog) -

 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());
 }

Here's the log of the error -

 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)

I've looked all over and I can't find a solution.

EDIT - This only happens when the user is not logged in. In that case, he presses the 'publish' button, logs in, and then the 'postOnWall' function is called, which generates the error. I'm working on it for 2 days now, and couldn't find anything about it.

Thanks!

like image 859
Tofira Avatar asked May 05 '11 13:05

Tofira


1 Answers

@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();
}
like image 87
Sanghoon-Jeong Avatar answered Oct 19 '22 15:10

Sanghoon-Jeong