Login callback is not triggered using facebook-android-sdk 4

回眸只為那壹抹淺笑 提交于 2019-12-06 01:37:30

问题


I have an activity for user to login with facebook. I used facebook-android-sdk v4.0.0. But login callback is not triggered when user click on login button. After showing progress bar, start previous activity automatically without showing any error on log instead of triggering login callback.

In SignUpActivity,

private CallbackManager callbackManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);

    callbackManager = CallbackManager.Factory.create();

    LoginButton loginButton = (LoginButton) findViewById(R.id.login_btn);
    loginButton.setReadPermissions(Arrays.asList("user_friends", "email"));
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.i("Login : ", "Success");
        }

        @Override
        public void onCancel() {
            Log.i("Login : ", "Cancel");
        }

        @Override
        public void onError(FacebookException e) {
            Log.e("Login Error : ", e.getMessage() + "");
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

I also added meta-data element to application element and the FacebookActivity to the manifest. Moreover, finished initializing facebook SDK in Application :

@Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     FacebookSdk.sdkInitialize(getApplicationContext());
}

What's wrong with my code ? Thanks for any suggestion !!

Edit

I found myself what's wrong with my code. I start SignUpActivity with no_history flag. After I remove that flag, everything is okay now.

来源:https://stackoverflow.com/questions/30233177/login-callback-is-not-triggered-using-facebook-android-sdk-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!