Muhammad Sadiq Alvi Muhammad Sadiq Alvi - 1 year ago 185
Android Question

Facebook Login CallbackManager FacebookCallback not called?

  • I trying to login with LoginButton but the login callbacks are not being called.(LoginButton is in a Fragment) .

  • FacebookSdk.sdkInitialize is called in the Application onCreate

  • No Callbacks are called after login is completed.
    Here is the Code:


public class FrameActivity extends BaseActivity {

public static CallbackManager callbackManager;
protected void onCreate(Bundle savedInstanceState) {
// FacebookSdk.sdkInitialize is called in the Application onCreate

callbackManager = CallbackManager.Factory.create();
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);



public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_login, container, false);
LoginButton loginButton = (LoginButton) view.findViewById(;
// If using in a fragment
// Other app specific specialization

// Callback registration
loginButton.registerCallback(FrameActivity.callbackManager, new FacebookCallback<LoginResult>() {
public void onSuccess(LoginResult loginResult) {

public void onCancel() {
// App code


public void onError(FacebookException exception) {
// App code

return view;

Please suggest the solution asap.

Answer Source

Try this:

  1. Init FacebookSdk.sdkInitialize() in fragment's onCreateView().

  2. Next line init callbackManager = CallbackManager.Factory.create();

  3. Implement on onActivityResult() in Fragment class.

  4. Add your callbackManager.onActivityResult(requestCode, resultCode, data); in fragment onActivityResult().

Make sure remove FacebookInit() and callbackManager from activity.