I use the LoginButton from the Facebook Android SDK to login to my application. How do I programmatically log out the user from any Activity?
Asked
Active
Viewed 1.9k times
8
MikkoP
- 4,864
- 16
- 58
- 106
-
Possible duplicate of [How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?](https://stackoverflow.com/questions/14328148/how-to-programmatically-log-out-from-facebook-sdk-3-0-without-using-facebook-log) – Ahmed Rajab Mar 24 '18 at 15:42
4 Answers
18
Starting Facebook SDK 4.0 you need to call
LoginManager.getInstance().logOut();
Tarun
- 13,727
- 8
- 42
- 57
-
2
-
Always check access token for null before this logout using logingManager.getInstance.logout(); – Pankaj kumar Jul 08 '15 at 09:18
8
Can you use closeAndClearTokenInformation() as described here: https://developers.facebook.com/docs/reference/android/current/class/Session/ ?
See also How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?
-
Thanks Flaxfield! Can you help with the other problem too, if you know something? http://stackoverflow.com/questions/24149499/cant-relogin-with-facebook-credentials-after-logout – MikkoP Jun 12 '14 at 08:48
1
If you are using facebook SDK 4, you first need to initialize sdk:
FacebookSdk.sdkInitialize(getApplicationContext());
And then :
LoginManager.getInstance().logOut();
AccessToken.setCurrentAccessToken(null);
Nimit Patel
- 11
- 2