I'd like to authenticate my users using the Facebook SSO service. I managed to handle basic login with the official Android Facebook sdk, which was quite painless, but it seems that the sdk just can't handle device rotation - at least I couldn't find a way to get it work correctly.
The auth code:
loginButtonFacebook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do FB login
facebook.authorize(LoginActivity.this, new DialogListener() {
@Override
public void onComplete(Bundle values) {
Toast.makeText(LoginActivity.this, "Facebook login successful", Toast.LENGTH_SHORT).show();
Log.d(TAG, "FACEBOOK LOGIN SUCCESSFUL");
//loginFB(facebook.getAccessToken());
}
@Override
public void onFacebookError(FacebookError error) {
Toast.makeText(LoginActivity.this, "FacebookError:" +error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
@Override
public void onError(DialogError e) {
Toast.makeText(LoginActivity.this, "Error: "+e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(LoginActivity.this, "Cancelled!", Toast.LENGTH_SHORT).show();
}
});
}
});
My Activity also needs to handle the result from the FB login activity:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
This works, but the facebook.authorize(...) method need a reference for my current Activity, so it can do a callback later. But if the device is rotated when the user is in the facebook authorization Activity, my previous Activity gets destroyed. So after the user authorizes my app., I don't get the callback about this.
Has anyone found a solution for this?
Thanks