Question

I am trying to login with Facebook using the Facebook Android SDK, however, the status callback is fired only once with OPENING session state. After that, a Facebook login activity appears with no content (I know it's that activity as it has the title that I've set for title_facebook_login in strings.xml) for a brief moment and disappears within a second. No other callback is fired, no exceptions, no crashes. It just waits forever at my initial activity. Here is my code:

Session.openActiveSession(parent, true, new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if(state == SessionState.OPENED){
                String accessToken = session.getAccessToken();
            }
        }
    });

Why wouldn't the callback fire for SessionState.OPENED (or CREATED, or even CLOSED) but only OPENING?

Was it helpful?

Solution

You need to call onActivityResult

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);
    }

So when login done . It comes to same activity and calls status callback with session state is opened

initialize UiLifecycleHelper

private UiLifecycleHelper uiHelper;

in oncreate need to call before setContentView

uiHelper = new UiLifecycleHelper(this, statusCallback);
        uiHelper.onCreate(savedInstanceState);

and need to maintain session in

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

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

    @Override
    protected void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top