title: Starting new activity after facebook login success
body: <p>I have been trying to start a new activity from a successful login attempt with facebook integration however when the login button is pressed after logging pin it returns to the same activity that the login button is on.</p>
  
  <p>I already have in place an intent to move to the next activity however it doesn't seem to have any response to success of the login.</p>
  
  <p>Here is my code (sorry for the untidiness I've been at this for a long time now):</p>
  
  <pre><code>import android.content.Intent;
  import android.support.v4.app.FragmentActivity;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.widget.TextView;
  import android.util.Log;
  
  import com.facebook.AccessToken;
  import com.facebook.CallbackManager;
  import com.facebook.FacebookCallback;
  import com.facebook.FacebookException;
  import com.facebook.FacebookSdk;
  import com.facebook.GraphResponse;
  import com.facebook.login.Login;
  import com.facebook.login.LoginManager;
  import com.facebook.login.LoginResult;
  import com.facebook.login.widget.LoginButton;
  import android.widget.Toast;
  import com.facebook.GraphRequest;
  import android.widget.ImageView;
  import android.widget.TextView;
  import com.bumptech.glide.Glide;
  import org.json.JSONObject;
  
  
      public class userlogin extends FragmentActivity {
  
          LoginButton loginButton; //The Facebook login button
          TextView loginstatus;
          CallbackManager callbackManager;
          private AccessToken accessToken;
  
  
          @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  FacebookSdk.sdkInitialize(getApplicationContext());
                  setContentView(R.layout.activity_userlogin);
                  loginButton = (LoginButton) findViewById(R.id.fb_login_button);
                  loginstatus = (TextView)findViewById(R.id.loginstatus);
                  callbackManager = CallbackManager.Factory.create();
                  loginButton.registerCallback(callbackManager, new FacebookCallback&lt;LoginResult&gt;() {
  
          // **Description: If the user cancels the login before it is completed a message will
          //                be shown to let them know that they are not logged in
          //**Parameters:
          //** Loginresult: the results of the login attempt.
          //**
          //**Precondition: loginButton must have been clicked first
          //**
          //**throws: N/A
          //** returns: a textView that displays a message of whether or not the login was succesful
  
              public void onSuccess(LoginResult loginResult) {
              loginstatus.setText("Login Success");
              accessToken = loginResult.getAccessToken();
  
              Toast.makeText(userlogin.this, "Eureka", Toast.LENGTH_LONG).show();
              GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
  
  
                  public void onCompleted(JSONObject object, GraphResponse response) {
                      Log.d("FB", "complete");
                      Log.d("FB", object.optString("name"));
                      Log.d("FB", object.optString("link"));
                      Log.d("FB", object.optString("id"));
                      Log.d("FB", object.optString("gender"));
                      TextView Username;
                      Username = (TextView) findViewById(R.id.loginstatus);
                      String id = object.optString("id");
                      String name = object.optString("name");
                      Username.setText("Welcome:" + name);
                      ImageView userPhoto = (ImageView) findViewById(R.id.facebookuserPortrait);
                      String i = "http://graph.facebook.com/" + id + "/picture?type=large";
                      Glide.with(userlogin.this).load(i).override(350, 350).into(userPhoto);
                      Intent intent = new Intent(userlogin.this, AlertsandPlanning.class);
                          startActivity(intent);
  
  
                  }
  
                  // **Description: If the user cancels the login before it is completed a message will
                  //                be shown to let them know that they are not logged in
                  //**Parameters: N/A
                  //**
                  //**Precondition: loginButton must have been clicked first
                  //**
                  //**throws: N/A
                  //** returns: a textView that displays a message
                  public void onCancel() {
                      loginstatus.setText("Login Canceled");
                  }
  
                  // **Description: If the user has an error during the login before it is completed
                  //                a message will be shown to let them know that they are not logged in
                  //**Parameters: FacebookException: an error transpoding if the login fails
                  //**
                  //**Precondition: loginButton must have been clicked first
                  //**
                  //**throws: Exception
                  //** returns: a textView that displays a message
                  public void onError(FacebookException exception) {
                      loginstatus.setText("Something went wrong \n+" +
                              "Check your credentials and try again");
  
                  }
              });
          }
  
          @Override
          public void onCancel() {
  
          }
  
          @Override
          public void onError(FacebookException error) {
  
          }
  
          protected void onActivivityResult(int requestCode, int resultCode, Intent data) {
              userlogin.super.onActivityResult(requestCode, resultCode, data);
              callbackManager.onActivityResult(requestCode, resultCode, data);
          }
  
  
      });
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I appreciate any insight given, I may start from scratch on this activity and try again if nothing seems to work.</p>
  
  <p>To reiterate the issue: The "Continue with facebook" button is clicked and the next activity shown is the userlogin activity instead of the AlertsandPlanning activity.</p>
  
  <p>update:</p>
  
  <p>I tried the current first comment here is the updated code,</p>
  
  <pre><code>import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.content.Intent;
  import com.facebook.CallbackManager;
  import com.facebook.login.widget.LoginButton;
  import com.facebook.FacebookSdk;
  import android.view.View;
  import com.facebook.login.LoginResult;
  import com.facebook.FacebookCallback;
  import org.json.JSONObject;
  import android.widget.Toast;
  import com.facebook.AccessToken;
  import com.facebook.login.LoginManager;
  import com.facebook.GraphResponse;
  import com.facebook.FacebookException;
  import com.facebook.GraphRequest;
  import com.facebook.GraphRequestAsyncTask;
      public class UserLogin extends AppCompatActivity implements View.OnClickListener {
  
  LoginButton btnFacebookLogin;
  CallbackManager callbackManager;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      FacebookSdk.sdkInitialize(getApplicationContext());
      setContentView(R.layout.activity_user_login);
      callbackManager = CallbackManager.Factory.create();
      setUI();
  }
  
  private void setUI() {
  
  
      btnFacebookLogin = (LoginButton) findViewById(R.id.FBLoginBtn);
  
      btnFacebookLogin.setOnClickListener(this);
      btnFacebookLogin.setReadPermissions("email", "public_profile");
  
  }
  
  @Override
  public void onClick(View v) {
      switch (v.getId()) {
  
          case R.id.FBLoginBtn:
              facebookLogin();
      }
  }
  
  private void facebookLogin() {
      // Callback registration
      btnFacebookLogin.registerCallback(callbackManager, new FacebookCallback&lt;LoginResult&gt;() {
          @Override
          public void onSuccess(LoginResult loginResult) {
  </code></pre>
  
  <p>// App code</p>
  
  <pre><code>            final AccessToken accessToken = loginResult.getAccessToken();
              GraphRequestAsyncTask request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
                  @Override
                  public void onCompleted(JSONObject user, GraphResponse graphResponse) {
                      LoginManager.getInstance().logOut();
                      String username = (user.optString("name"));
                  }
              }).executeAsync();
  
  
              Toast.makeText(getApplicationContext(), "Login Success with facebook", Toast.LENGTH_SHORT).show();
              Intent startAlertsAndPlanning = new Intent(UserLogin.this, AlertsAndPlanning.class);
              startActivity(startAlertsAndPlanning);
  
  
          }
  
          @Override
          public void onCancel() {
              // App code
          }
  
          @Override
          public void onError(FacebookException exception) {
              // App code
          }
      });
  
  }
  
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      callbackManager.onActivityResult(requestCode, resultCode, data);
  }
  </code></pre>
  
  <p>}</p>