Unexpected call to LoginManager.onActivityResult - Facebook SDK Android

Viewed 87

My Dependency

dependencies {
    implementation 'com.facebook.android:facebook-login:11.0.0'
}

I've been using a LoginButton for moths without any problem but since today after call to login if the users have not logged before in my app the login flow seems to works fine but the onError method of my FacebookCallback is called and I have the next error Unexpected call to LoginManager.onActivityResult and the second time that I call login it works and I don't have the Unexpected call to LoginManager.onActivityResult error.


Here the complete code of my Activity

package app.meedu.flutter_facebook_auth;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;

public class MainActivity extends AppCompatActivity {

    private final CallbackManager callbackManager = CallbackManager.Factory.create();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final LoginButton  button = (LoginButton) findViewById(R.id.login_button);
        button.setPermissions("public_profile,email");
        button.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                // App code
                Log.i("GOOD::","exito");
            }

            @Override
            public void onCancel() {
                // App code
            }

            @Override
            public void onError(FacebookException exception) {
                // App code
                Log.i("ERROR::",exception.getMessage());
            }
        });
    }

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

Your project might be in development mode, switch to live mode might solve the problem

Related