Nilesh Verma
Nilesh Verma

Reputation: 924

Logout in Facebook Using android fb SDK 3.0

my app using android facebook sdk 3.0,after login getting some response,after that i need to signout from facebook clicking on button.

How to log-out from the session in facebook pls help

Upvotes: 8

Views: 9163

Answers (2)

Rikin Prajapati
Rikin Prajapati

Reputation: 1943

This method will help you to logout from facebook programmatically in android

/**
 * Logout From Facebook 
 */
public static void callFacebookLogout(Context context) {
    Session session = Session.getActiveSession();
    if (session != null) {

        if (!session.isClosed()) {
            session.closeAndClearTokenInformation();
            //clear your preferences if saved
        }
    } else {

        session = new Session(context);
        Session.setActiveSession(session);

        session.closeAndClearTokenInformation();
            //clear your preferences if saved

    }

}

Upvotes: 7

Jorge Garcia
Jorge Garcia

Reputation: 680

You should do something like this.

if (Session.getActiveSession() != null) {
    Session.getActiveSession().closeAndClearTokenInformation();
}

Session.setActiveSession(null);

Also if you store the user token in some other way you should clear that too.

Upvotes: 26

Related Questions