Goose Goose - 4 years ago 227
Android Question

Android API IsConnected returning TRUE after Signing Out

I am developing a game for Android using Google Play Game Services, using Xamarin. I am doing my testing using a Genymotion Android Emulator. I have run into an issue that appears to be a bug in either Google Play or Xamarin's implementation.

If I sign out of a Google account, calls to the IGoogleApiClient.IsConnected() continue to return true (even though I have clearly just signed out). If I then attempt to use that API object, I will get exceptions like:

java.lang.SecurityException: Not signed in when calling API

For example, the follow code results in the above exception if executed after signing out:

public void StartNewMatch()
if (!mGoogleApiClient.IsConnected)

Intent intent = GamesClass.TurnBasedMultiplayer.GetSelectOpponentsIntent(mGoogleApiClient, 1, 1, true);
StartActivityForResult(intent, RC_SELECT_PLAYERS);

I am signing out in the Google Play Games Inbox (match picker); as shown in the images below.

Anyone run into this before? Am I missing something? Got any work-arounds?

Note: This only occurs if signing out through Google's UI. If I manually sign the user out, with something like
, the issue does not occur;
now returns false (as expected).

enter image description here

enter image description here

enter image description here

Answer Source

In order to keep signed-in state synced up you MUST implement onActivityResult properly.

This should look something as follows:

NOTE: this is java code, I am not sure how this will look exactly using Xamarin, but hopefully you should be able to figure it out :)

protected void onActivityResult(int requestCode, int responseCode, Intent data) {

    // check for "inconsistent state"
    if ( responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED && requestCode == <your_request_code_here> )  {  

       // force a disconnect to sync up state, ensuring that mClient reports "not connected"

NOTE: just make sure to replace in the code with the request code you used. You may need to check for multiple request codes too.

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