keyboard keyboard - 1 year ago 74
Java Question

Google SignIn on Android - Log out does not work since not logged in

I have integrated Google SignIn via this guide (

I've done setup like this:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)

GoogleSignIn.googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)

Sign in works with the following code and works perfectly fine:

public static void loginGoogleSDK()
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
GameApplication.getActivity().startActivityForResult(signInIntent, RC_SIGN_IN);

The SignIn-Overlay appears, I choose an account and log in. Everything works fine.

Then I try to call logout with the following code after this guide (, but I always the the error message: Cannot log out, since not logged in.

new ResultCallback<Status>() {
public void onResult(Status status) {
System.out.println("Google SDK Sign Out Access Status:" + status);

The weird part is, that if I call login again, it is automatically successful and I can not choose an account again. Hence, the login is still active and I can not log out.

Answer Source

Per the enableAutoManage documentation, including it:

Enables automatic lifecycle management in a support library FragmentActivity that connects the client in onStart() and disconnects it in onStop().

It handles user recoverable errors appropriately and calls onConnectionFailed(ConnectionResult) on the unresolvedConnectionFailedListener if the ConnectionResult has no resolution. This eliminates most of the boiler plate associated with using GoogleApiClient.

By not including enableAutoManage() like the Add Sign In guide does, your GoogleApiClient never actually connects, causing the error you are experiencing.

If you don't want to use enableAutoManage(), you can follow the instructions to manually manage connections including providing an implementation for ConnectionCallbacks and OnConnectionFailedListener.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download