Java Android Facebook连接按钮需要点击两次

Java Android Facebook连接按钮需要点击两次,java,android,Java,Android,几个小时以来,我一直在想为什么我的facebook连接不能正常工作。我总是要点击它两次。。第一次单击它时,我看到Facbook对话框正在打开,但它没有调用任何类型的回调,因此我的登录活动正在恢复 public void onClick_fbIcon(View v) { if(!buttonsEnabled) return; buttonsEnabled = false; tryFacebookConnect(); } @SuppressWarnings

几个小时以来,我一直在想为什么我的facebook连接不能正常工作。我总是要点击它两次。。第一次单击它时,我看到Facbook对话框正在打开,但它没有调用任何类型的回调,因此我的登录活动正在恢复

public void onClick_fbIcon(View v) {
    if(!buttonsEnabled)
        return;

    buttonsEnabled = false;
    tryFacebookConnect();
}

@SuppressWarnings("deprecation")
private void tryFacebookConnect() {
    Log.d("debug", "start fbc");
    doingFacebooklogin = true;
    facebook.authorize(this, new DialogListener() {
        public void onComplete(Bundle values) {
            end();
            toast("Complete");
            Log.d("debug", "#0");   
            // .. continue with main code
        }

        public void onFacebookError(FacebookError error) {
            end();
            Log.d("debug", "#1");           
        }

        public void onError(DialogError e) {
            end();
            Log.d("debug", "#2");
        } 

        public void onCancel() {
            end();
            Log.d("debug", "#3");
        }

        private void end() {
            Log.d("debug", "fbc complete");
            doingFacebooklogin = false;
        }
    });
}
第一次单击我只得到启动fbc,但之后什么也没有,所以我猜没有调用回调方法

@SuppressWarnings("deprecation")
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("debug", "Main: onActivityResult");
    super.onActivityResult(requestCode, resultCode, data);

    facebook.authorizeCallback(requestCode, resultCode, data);
}
我发现当facebook连接第一次不工作时,会调用onResume。下次调用onActivityResult时

@SuppressWarnings("deprecation")
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("debug", "Main: onActivityResult");
    super.onActivityResult(requestCode, resultCode, data);

    facebook.authorizeCallback(requestCode, resultCode, data);
}
我的登录活动是由我的主活动启动的意图,它指定是否需要登录:

    Intent intent = new Intent(this, Login.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(intent);
有时我会看到以下错误:

11-22 10:23:39.684: D/Facebook-publish(7317): Can NOT get FbInjector instance! Probably because this method was called in ContentProvider's onCreate.

请看一下本教程。我只是遵循这一点,我使所有的工作完美

希望它也能帮助你


我不知道为什么,但问题显然是facebook sdk的一部分。我发现,如果我的设备上没有安装facebook应用程序,则不会出现此问题。所以我改变了我的代码如下:

facebook.authorize(a, new String[] { }, **Facebook.FORCE_DIALOG_AUTH**, new DialogListener() {
...

谢谢,但这对我来说没有任何改变。