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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With