I am new to android development. I am trying to implement login through facebook using facebook SDK 4.0.0. Login is successful but it stays in the same activity for a second, the button changes to Logout and then the second activity appears. I want it to directly move to second activity. I searched for it but I couldn't figure it out.
(The viewflipper is calling next layout which is just a progress bar)
Following is my code.
public class MainActivity extends ActionBarActivity {
private String name;
private String lname;
private LoginButton loginButton;
private ProfileTracker mProfileTracker;
private CallbackManager mCallBackManager;
private AccessTokenTracker mAccessTracker;
SharedPreferences sp;
private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken atoken = loginResult.getAccessToken();
ViewFlipper vp = (ViewFlipper) findViewById(R.id.flip);
vp.showNext();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
};;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sp = getPreferences(MODE_PRIVATE);
if (sp.contains("username")) {
Intent i = new Intent(this, userSelect.class);
i.putExtra("username", sp.getString("username", "noUser"));
i.putExtra("lname", sp.getString("lastname", "nomail"));
startActivity(i);
}
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions("email");
mCallBackManager = CallbackManager.Factory.create();
loginButton.registerCallback(mCallBackManager, mCallBack);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (sp.contains("username")) {
Intent i = new Intent(this, userSelect.class);
i.putExtra("username", sp.getString("username", "noUser"));
i.putExtra("lname", sp.getString("lastname", "nomail"));
startActivity(i);
}
mCallBackManager.onActivityResult(requestCode, resultCode, data);
mAccessTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) {
}
};
mProfileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) {
if ( newProfile != null)
{
name = newProfile.getFirstName();
lname = newProfile.getLastName();
Intent intent = new Intent(MainActivity.this, userSelect.class);
Editor editor = sp.edit();
editor.putString("username", name);
editor.putString("lastname",lname );
editor.commit();
intent.putExtra("username", name);
intent.putExtra("lname",lname);
startActivity(intent);
}
}
};
mAccessTracker.startTracking();
mProfileTracker.startTracking();
}
}