I have a SettingsActivity
where there are several options including finding Facebook friends and logging out. So when a user chooses to find her Facebook friend
in Facebook SDK v4 we can log out using
LoginManager.getInstance().logOut();
note that don't forget to initialize sdk like this
FacebookSdk.sdkInitialize(getApplicationContext());
private Session.StatusCallback statusCallback = new SessionStatusCallback();
logout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Session.openActiveSession(this, true, statusCallback);
}
});
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state,
Exception exception) {
session.closeAndClearTokenInformation();
}
}
You should pass session variable through Parcelable interface and clear session through that session variable. Pass facebook session like this : Passing a Facebook session across activities
Using Facebook SDK v4 you can do the following:
if (AccessToken.getCurrentAccessToken() != null) {
LoginManager.getInstance().logOut();
}
You can take a look at the LoginManager class.
Do like this
try {
Session.getActiveSession().closeAndClearTokenInformation();
} catch (Throwable e) {
e.printStackTrace();
}
Try this below code for session clear in facebook integration android.
Put below method in your activity and call before the login to facebook.
public static void fbClearToken(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
}
}
For me it's working... Hope this is helpful for you...