Question

I have the below onclick for a facebook login button:

fblogin.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Session session = Session.getActiveSession();
                if (session == null) {
                    Session.openActiveSession(LogIn.this, true,
                            statusCallback);
                } else if (!session.isOpened()) {
                    session.openForRead(new Session.OpenRequest(
                            LogIn.this).setCallback(statusCallback)
                            .setPermissions(permissions)
                            );
                }
            }
        });

And then have the below logout onclick:

private OnClickListener OnClick_logout = new OnClickListener() {
        public void onClick(View v) {
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("loggedIn", false);
            editor.putString("email", "");
            editor.putString("password", "");
            editor.commit();
            db.clearLists();
            db.clearProducts();
            Intent intent = new Intent(v.getContext(), Splash.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
            v.getContext().startActivity(intent);
        }
    };

Currently this does not logout facebook which means when the user goes back to the LogIn activity and trys to click the fblogin button nothing happens.

What would I need to add to my logout onclick to actually log facebook out so that the user can press the fblogin button again and login again.

I have tried adding to the logout button:

    Session.getActiveSession().closeAndClearTokenInformation();

However when I then go back to the login screen and click the login button I get:

10-30 10:51:14.776: E/AndroidRuntime(18964): java.lang.UnsupportedOperationException: Session: an attempt was made to open an already opened session. 
Was it helpful?

Solution

Try adding:

Session.getActiveSession().closeAndClearTokenInformation();
Session.setActiveSession(null);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top