suresh cheemalamudi
suresh cheemalamudi

Reputation: 6240

Android - facebook sdk issues

I have included Fb login in my app, When i click on "Log in" button ( com.facebook.widget.LoginButton), it is opening an extra activity with dialog before logging in as shown in the pic below. why is this happening? I dont want to open this extra activity before logging in. any idea how to do this?

enter image description here

enter image description here

my main activity:

public class MainActivity extends SherlockFragmentActivity {

    //Button fblogin;
    Button signup_with_email;
    Button log_in;
    private UiLifecycleHelper uiHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        uiHelper = new UiLifecycleHelper(this, null);
        uiHelper.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initialize();
        setListeners();

    }

    private void initialize() {
        //fblogin = (Button) findViewById(R.id.login_button);
        signup_with_email = (Button) findViewById(R.id.signup_with_email);
        log_in = (Button) findViewById(R.id.log_in);
    }

    private void setListeners() {

        /*fblogin.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

            }
        });
*/
        signup_with_email.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                startActivity(new Intent(MainActivity.this,
                        EmailSignUpActivity.class));
            }
        });

        log_in.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, LoginActivity.class));
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        uiHelper.onResume();

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);
        startActivity(new Intent(MainActivity.this, DashBoardActivity.class));
    }

    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

Upvotes: 3

Views: 818

Answers (2)

wkarl
wkarl

Reputation: 809

I'm a bit late to the party but the accepted answer is wrong.

After some digging into the SDK code this is what I found: Facebook starts com.facebook.LoginActivity for the login process and since you didn't specify a custom Theme, it'll show up as in your screenshot. This is the JavaDoc for LoginActivity:

This Activity is a necessary part of the overall Facebook login process but is not meant to be used directly. Add this activity to your AndroidManifest.xml to ensure proper handling of Facebook login.

They suggest to use Theme.Translucent.NoTitleBar:

<activity android:name="com.facebook.LoginActivity"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:label="@string/app_name" />   

However, if you use the suggested Theme the Activity will be translucent but still display a indeterminate ProgressBar in the middle (the animated loading symbol).

Personally, I prefer to use a DialogFragment to indicate the loading process and not display Facebook's LoginActivity at all:

<activity
    android:name="com.facebook.LoginActivity" 
    android:theme="@android:style/Theme.NoDisplay" />

Upvotes: 2

Matt Accola
Matt Accola

Reputation: 4142

You are passing null as the second parameter to UiLifecycleHelper's constructor. You need to pass an instance of Session.StatusCallback. The Facebook SDK tutorials typically show this as a final field in your Activity like this

private Session.StatusCallback callback = 
    new Session.StatusCallback() {
    @Override
    public void call(Session session, 
            SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

Then you implement onSessionStateChange to do whatever you need to do when the session is opened or closed...in your case it looks like you want to start the DashBoardActivity when the session state goes to opened.

In any event there will be a brief period where you see a dialog because during the Facebook SDK SSO process control is temporarily passed to the native Facebook app to do the authorization. Once the authorization is complete control is passed basck Session.StatusCallback is invoked.

Upvotes: 1

Related Questions