从几个小时后我就想弄清楚为什么我的facebook-connect无法正常工作。我总是要点击它两次..第一次点击它我看到facbeook对话框正在打开,但它没有调用任何类型的回调所以我的登录活动只是“恢复”。
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;
}
});
}
第一次点击我只得到“start fbc”但之后没有任何内容,所以我猜没有调用回调方法。
我发现当facebook-connect第一次没有工作时,“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.
答案 0 :(得分:0)
答案 1 :(得分:0)
我不知道为什么但问题显然是facebook-sdk的一部分。我发现如果我的设备上没有安装facebook-app,则不会出现此问题。所以我改变了我的代码:
facebook.authorize(a, new String[] { }, **Facebook.FORCE_DIALOG_AUTH**, new DialogListener() {
...