1

I am doing simple google login and logout using API. but when i logout using below code, sometimes googleapiclient not disconnect. and because of that when i am going for login, it will automatic login to my previous account rather that asking for select account.

Code for logout:

public void googlePlusLogout() {
        if (mGoogleApiClient.isConnected()) {
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
            mGoogleApiClient.disconnect();
            Log.e("APPLICATION", "DISCONNECTED");

        }

when i call above method for logout, sometimes mGoogleApiClient.disconnect() not called. help me with this problem.

Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99

2 Answers2

0

There is a new API try this:

    @Override
public void logOut() {
    if (googleApiClient.isConnected()) {
        signOut();
        revokeAccess();
        googleApiClient.disconnect();
    }
}

private void signOut() {
    Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    App.logger().d(TAG, "signOut: status = " + status);
                }
            });
}

private void revokeAccess() {
    Auth.GoogleSignInApi.revokeAccess(googleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    App.logger().d(TAG, "revokeAccess: status = " + status);
                }
            });
}
Raz Tourgman
  • 567
  • 5
  • 9
0

After many memory leaks, this is what I came up with. No more memory leaks. Is it verbose? yes. Is it too verbose? perhaps. Does it work? yes.

 if (mGoogleApiClient !=null) if (mGoogleApiClient.isConnected()) LocationServices.FusedLocationApi.removeLocationUpdates(this);
 if (mGoogleApiClient !=null) mGoogleApiClient.unregisterConnectionCallbacks(this);
 if (mGoogleApiClient !=null) mGoogleApiClient.unregisterConnectionFailedListener(this);
 if (mGoogleApiClient !=null) if (mGoogleApiClient.isConnected()) mGoogleApiClient.disconnect();
 mGoogleApiClient =null;
seekingStillness
  • 4,833
  • 5
  • 38
  • 68