8

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?

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 Answers4

18

Starting Facebook SDK 4.0 you need to call

LoginManager.getInstance().logOut();
Tarun
  • 13,727
  • 8
  • 42
  • 57
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?

Community
  • 1
  • 1
Roemer
  • 3,566
  • 1
  • 16
  • 32
  • 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
4

If you are using facebook SDK 4, you first need to initialize sdk:

FacebookSdk.sdkInitialize(getApplicationContext());

And then just do:

LoginManager.getInstance().logOut();

See here for more details.

Rob
  • 748
  • 2
  • 7
  • 16
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);