Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listen for Facebook logout with the LoginButton. (4.1)

I've been reading and haven't found a solution yet. So here goes.

I'm trying to upgrade to Facebook's new SDK 4.1 Android SDK. I can successfully log in a user using the Facebook's LoginButton using this code: facebookLogin.registerCallback(callbackManager, new FacebookCallback<LoginResult>()....

Once a user is logged in, I want to know when a user logs using the same button. The login button changes to say "Log out" when a user is logged in. What I want to know, is how can I listen for a successful log out from the LoginButton? ( I know thatLoginManager.getInstance().logOut(); can log a user out. But what I'm looking for is some sort of callBack which I can handle accordingly.)

like image 279
joels Avatar asked May 04 '15 20:05

joels


People also ask

How do I log out of Facebook on Chrome?

Log out on a computerClick the downward-facing triangle in the top right corner, then click "Log Out" in the dropdown menu that appears.


1 Answers

Quoting the Facebook SDK Upgrading the Android SDK from 4.0.1 to 4.1.0 docs: "Replacement Classes - Session and UserSettingsFragment have been removed and replaced by the LoginManager and AccessToken classes. LoginActivity is replaced by FacebookActivity."

Because I wanted to mimic the old Sessions changed listener logic, I looked further into the AccessTokenTracker. Here's how I solved my problem. I still use Facebook's LoginButton to Log out the user, but I also include this to listen for a change to a null token. Meaning the user logged out.

private AccessTokenTracker fbTracker;
    ...
    fbTracker = new AccessTokenTracker() {
                @Override
                protected void onCurrentAccessTokenChanged(AccessToken accessToken, AccessToken accessToken2) {
                    if (accessToken2 == null) {
                        Log.d("FB", "User Logged Out.");
                    }
                }
            };

Hope this helps others in the future.

like image 172
joels Avatar answered Sep 24 '22 01:09

joels