title: Facebook login button in Android returns user to the same page after logging in
body: <p>I currently have a Facebook login button in my main activity and want the user to view a new fragment after logging in. However, as it stands, the user gets taken back to the main activity after logging in and I'm not sure why. I defined the button in XML:</p>
  
  <pre><code>&lt;com.facebook.login.widget.LoginButton
          xmlns:facebook="http://schemas.android.com/apk/res-auto"
          facebook:com_facebook_login_text="FACEBOOK"
          android:id="@+id/login_button"
          android:layout_width="230dp"
          android:layout_height="30dp"/&gt;
  </code></pre>
  
  <p>and in my MainActivity in <code>onCreate()</code> I initialised the button:</p>
  
  <pre><code>fbLogIn = (LoginButton) findViewById(R.id.login_button);
  fbLogIn.setReadPermissions("user_friends");
  fbLogIn.registerCallback(FbFragment.mCallBackManager, FbFragment.mCallBack);
  </code></pre>
  
  <p>FbFragment is the Fragment I want the user to be taken to after logging in via the button - and it contains stuff like the CallbackManager: </p>
  
  <pre><code>public class FbFragment extends Fragment {
      private static TextView mTextDetails;
      public static CallbackManager mCallBackManager = CallbackManager.Factory.create();;
      public static FacebookCallback&lt;LoginResult&gt; mCallBack = new FacebookCallback&lt;LoginResult&gt;() {
  
          @Override
          public void onSuccess(LoginResult loginResult) {
              AccessToken accessToken = loginResult.getAccessToken();
          }
  
          @Override
          public void onCancel() {
          }
  
          @Override
          public void onError(FacebookException e) {
          }
      };
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          return inflater.inflate(R.layout.login_fragment, container, true);
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          mCallBackManager.onActivityResult(requestCode, resultCode, data);
      }
  }
  </code></pre>
  
  <p>I can't figure out why this Fragment never gets displayed. Out of desperation I even tried setting up an onClickListener() in MainActivity where FbFragment gets initialised every time the button gets clicked but that didn't work either (unsurprisingly). </p>
  
  <p>Any ideas? Highly grateful for any help, thanks</p>