Android Facebook SDK openActiveSession(…) doesn’t trigger callback


I'm working on an app that uses Facebook login. On app startup, calling Session.getActiveSession() returns null. I have a check to see if the session is null and if it is, run the method Session.openActiveSession(Activity activity, boolean allowLoginUI, StatusCallback callback).

I want to keep the boolean in that method set to false because I want to send the user to a custom login activity if needed, and setting that parameter to true brings up the basic login permissions window (not desired). But when I set the parameter to false, the method doesn't even trigger a session state change and doesn't trigger the associated callback (the third parameter). If I set the parameter to true, and then back out of the subsequent dialog, the callback triggers.

UPDATE: The purpose is to initialize the Session object without using the standard LoginUi. I've tried everything I can think of and nothing will initialize the session. If the user hasn't logged in, I want to change to another Activity where I have a standard LoginButton.

Here's the code I'm using:

public void onCreate(Bundle savedInstanceState) {

    Session.StatusCallback callback = new Session.StatusCallback() {
        public void call(Session session, SessionState state, Exception exception) {
            Log.i("MainActivity", "calling session callback");
            onSessionStateChange(session, state, exception);
    session = Session.getActiveSession();
        Log.i("MainActivity", "session is null");
        Session.openActiveSession(this, false, callback);
            Log.i("MainActivity", "session is closed");
            startActivityForResult(new Intent("<custom login activity>"), LOGIN_REQUEST);
        else if(session.isOpened()){
            Log.i("MainActivity", "session is opened");
    uiHelper = new UiLifecycleHelper(this, callback);

Best Solution

Of course after I put up a bounty, I figure it out.

First I check if the Session is null, which it seems to be every time I start the app anyway, so that may not be necessary. But the key is to check the return value of the method used to open the active session and go to the login activity if it returns null. That way I'm not just checking the return value of the Session, but the return value of the method.

if(Session.openActiveSession(this, false, callback) == null){
    //Start login activity