title: Android Firebase Oauth Facebook not working in fragment
body: <p>Authenticating with Firebase Facebook is not working, here is my fragment code:</p>
  
  <pre><code>public class LoginFragment extends Fragment {
  
  private View mView;
  
  private FirebaseAuth mAuth;
  private FirebaseAuth.AuthStateListener mAuthListener;
  private CallbackManager mCallbackManager;
  
  public LoginFragment() {
      // Required empty public constructor
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      mView = inflater.inflate(R.layout.fragment_login, container, false);
      loginFacebook();
      mAuth = FirebaseAuth.getInstance();
  
      mAuthListener = new FirebaseAuth.AuthStateListener() {
          @Override
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
              FirebaseUser user = firebaseAuth.getCurrentUser();
  
              if (user != null) {
                  // User is signed in
                  //Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
              } else {
                  // User is signed out
                  //Log.d(TAG, "onAuthStateChanged:signed_out");
              }
              // ...
          }
      };
  
      return mView;
  }
  
  
  private void loginFacebook() {
      // Initialize Facebook Login button
      mCallbackManager = CallbackManager.Factory.create();
      LoginButton loginButton = (LoginButton) mView.findViewById(R.id.login_button);
      loginButton.setReadPermissions("email", "public_profile");
      loginButton.registerCallback(mCallbackManager, new FacebookCallback&lt;LoginResult&gt;() {
          @Override
          public void onSuccess(LoginResult loginResult) {
              //Log.d(TAG, "facebook:onSuccess:" + loginResult);
              handleFacebookAccessToken(loginResult.getAccessToken());
          }
  
          @Override
          public void onCancel() {
              //Log.d(TAG, "facebook:onCancel");
              // ...
          }
  
          @Override
          public void onError(FacebookException error) {
              //Log.d(TAG, "facebook:onError", error);
              // ...
          }
      });
  }
  
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      // Pass the activity result back to the Facebook SDK
      mCallbackManager.onActivityResult(requestCode, resultCode, data);
  }
  
  @Override
  public void onStart() {
      super.onStart();
      mAuth.addAuthStateListener(mAuthListener);
  }
  
  @Override
  public void onStop() {
      super.onStop();
      if (mAuthListener != null) {
          mAuth.removeAuthStateListener(mAuthListener);
      }
  }
  
  private void handleFacebookAccessToken(AccessToken token) {
      //Log.d(TAG, "handleFacebookAccessToken:" + token);
  
      AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
      mAuth.signInWithCredential(credential)
              .addOnCompleteListener((MainActivity)getActivity(), new OnCompleteListener&lt;AuthResult&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                      //Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
  
                      // If sign in fails, display a message to the user. If sign in succeeds
                      // the auth state listener will be notified and logic to handle the
                      // signed in user can be handled in the listener.
                      if (!task.isSuccessful()) {
                          //Log.w(TAG, "signInWithCredential", task.getException());
                          Toast.makeText((MainActivity)getActivity(), "Authentication failed.",
                                  Toast.LENGTH_SHORT).show();
                      }
  
  
                  }
              });
  }
  }
  </code></pre>
  
  <p>After the Facebook popup comes and I enter my username and password, nothing in the code is firing when in debug mode.</p>
  
  <p>The Firebase user is always <strong>null</strong>. What am I doing wrong ?
  After signing in it logs Log.d("LOGGER", "onAuthStateChanged:signed_out");</p>
  
  <p>PS: The exact same code works when inserted in <strong>MainActivity</strong></p>