Recently, Facebook released SDK 4 with new and cool updates. I tried to switch into SDK4 to use new features, however, I am struggling with the Login feature of Facebook.
So far, to log out Facebook programmatically, I used :
Session session = Session.getActiveSession();
session.closeAndClearTokenInformation();
But SDK4 seems not to support Session anymore, and in official docs, they mention:
There are two ways to implement Facebook login on Android:
LoginButton class - Which provides a button you can add to your UI. It follows the current access token and can log people in and out.
Well, seems there's no way to log out Facebook programmatically except using LoginButton. Anyone have any idea, please share it here.
To handle it with the loginButton:
You can logout by using LoginManager but you have to use graph request also. I am talking about log out completely so, that next time you can login with different account.
By the help of shared preferences here you can logout completely, and next time you can login with different account.
You can use
LoginManager.logOut()
Check out https://developers.facebook.com/docs/reference/android/current/class/LoginManager/
SDK4, if you want to completely de-couple, make sure you also remove the app from the user's facebook account. This method disconnects the user completely:
You can use
LoginManager.getInstance().logOut();
, even if you use LoginButton becauseEDIT: Just to mention that this works for Facebook SDK v4. I don't know if they will change it in the future.
@as batoutofhell mention, don't forget to put
FacebookSdk.sdkInitialize(getApplicationContext());
to initialize the facebook sdk. Please see here for the details.