Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
    {
        return;
    }

    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 mGoogleApiClient.Disconnect(), the issue does not occur; mGoogleApiClient.IsConnected() now returns false (as expected).

enter image description here

enter image description here

enter image description here

like image 754
Goose Avatar asked Nov 13 '14 06:11

Goose


1 Answers

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 :)

@Override
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"
       mGoogleApiClient.disconnect();
    }
}

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.

like image 93
free3dom Avatar answered Nov 14 '22 09:11

free3dom