Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook SDK 4.0 external logout

enter image description here

I've succesfully updated my Login code for FB SDK 4.0. Initially, I used this code to logout from Facebook from an external dialog.

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

    Session.setActiveSession(null);

But with the new FB SDK 4.0, there is no way I use this. I've tried using

  LoginManager loginManager = LoginManager.getInstance();
    loginManager.logOut();

but got the following error which I cannot explain.

       at com.facebook.internal.Validate.sdkInitialized(Validate.java:99)
        at com.facebook.login.LoginManager.<init>(LoginManager.java:70)
        at com.facebook.login.LoginManager.getInstance(LoginManager.java:81)
        at    com.ababab.abab_name_changed.common.util.CommonUtils.fbLogout(CommonUtils.java:676)
like image 361
Prachi Avatar asked Dec 08 '22 04:12

Prachi


1 Answers

LoginManager.getInstance().logOut();

Works for me.

I think you'll have to call

FacebookSdk.sdkInitialize(getApplicationContext());

before you ask the LoginManager to logout.

like image 85
Jack Tsai Avatar answered Dec 11 '22 10:12

Jack Tsai