2

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

Zsombor Erdődy-Nagy
  • 16,864
  • 16
  • 76
  • 101

2 Answers2

1

I usually hate recommending this, but the Activity that Facebook uses can be locked to portrait without any negative consequences. All it does is show an indefinite ProgressBar.

Check your manifest for the activity with the name com.facebook.LoginActivity and make sure it has the following properties:

<activity
    android:configChanges="keyboardHidden"
    android:name="com.facebook.LoginActivity"
    android:screenOrientation="portrait" />
Austyn Mahoney
  • 11,398
  • 8
  • 64
  • 85
1

in your manifest file under your activity name just add the following line

android:configChanges="orientation"

inside your activity

@Override
public void onConfigurationChanged(Configuration newConfig) 
{
    super.onConfigurationChanged(newConfig);
    ................
}

Refer here and here

Siva K
  • 4,968
  • 14
  • 82
  • 161