Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook logout does not work Android [Facebook sdk 4]


I'm developing a game for Android that has Facebook login and I faced the following weird behaviour when trying to logout:
if user press Facebook logout button, closes the app and then reopens again, the user is still logged in (= access token still valid). As a test, I checked the access token after logout and it is null as it should be, but if I close and reopen the app then the access token is again not null.
It seems that Facebook caches the access token and takes it from cache even after logout.

I tried using native Facebook button and also LoginManager.getInstance.logout(); I have initialized Facebook sdk on the top of the onCreate, before setContent() and I followed the procedure on Facebook docs, but same result.

I'm using Facebook sdk 4.6.0 and I faced this problem on Android 4.2.2 and 4.4.2.

EDIT

Here's the code:

- Facebook button:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_settings);
    btnFacebookLogout.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException e) {

        }
    });
}



- normal button:

btnNormalLogout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LoginManager.getInstance().logOut();
        }
    });

Any suggestion?

Thanks in advance

like image 973
mirko flauto Avatar asked Dec 08 '15 18:12

mirko flauto


1 Answers

Well, i`ve been fighting that damn sdk for about an hour and discovered a simple workaround for that logout issue.

Just try to do the following: LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY)

Pros: LoginManager.getInstance().logOut() works fine in this case.

Cons: the authentication will always appear in a webview dialog.

like image 153
Ontoshgo Avatar answered Oct 11 '22 04:10

Ontoshgo