I use Google Game Services for leaderboards. Showing it like this:
static public void showLeaderboard(String lid)
{
if (isLogined() == 1)
{
Log.i(TAG, "Showing leaderboard...");
Intent intent = Games.Leaderboards.getLeaderboardIntent(mClient, lid);
mApp.startActivityForResult(intent, 1);
}
}
static public int isLogined()
{
if (mClient != null && mClient.isConnected())
return 1;
return 0;
}
But when I open leaderboards and logout from Google Game Services with Google UI (Action Overflow menu icon -> Settings -> Sign out) I keep having my isLogined() == 1. So, when I call showLeaderboard() second time - game falls with exception:
java.lang.SecurityException: Not signed in when calling API
GoogleApiClient has callbacks for connection but not for disconnection. How can I handle sing out from GGS with google UI?
In order to keep everything synced up you MUST implement onActivityResult
properly.
This should look something as follows:
@Override
protected void onActivityResult(int request, int response, 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"
mClient.disconnect();
}
}
NOTE: just make sure to replace <your_request_code_here>
in the code with the request code you used (which is just 1
in your example). You may need to check for multiple request codes if you use achievements as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With