When the leader board is shown in the screen there is a option called "setting". Inside that there is a option "Signout". When I clicked signout the leaderboard is closed,
If I checked the sign in status the the below function always returns true. Means that the mGoogleApiClient is connected. and hence when I tried to click the icon which shows the leaderboard it always has the responseCode RESULT_RECONNECT_REQUIRED.
This issue goes away if i restart my App
public boolean isSignedIn() {
return mGoogleApiClient != null && mGoogleApiClient.isConnected();
}
How do the program knows that the user has signed-out in the leaderboard screen.
You have to catch the signout in onActivityResult
and call GoogleApiClient.disconnect()
yourself since the connection is in an inconsistent state (source).
So, when you open the leaderboard using the following code:
activity.startActivityForResult(Games.Leaderboards.getLeaderboardIntent(googleApiClient, leaderboardId), MY_CUSTOM_LEADERBOARD_RESULT_CODE);
You should handle the signout event as follows:
public void onActivityResult(int requestCode, int responseCode, Intent intent) {
boolean userLoggedOut = (responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) && (requestCode == MY_CUSTOM_LEADERBOARD_RESULT_CODE);
if (userLoggedOut) {
googleApiClient.disconnect();
}
}
You should handle the RESULT_RECONNECT_REQUIRED by calling reconnect().
If there was a transient error with the connection, this will silently reconnect the player. If they did actually signout, onConnectionFailed() will be called, and you can reset the UI/game to be appropriate for the not logged in state.
if (resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
mGoogleApiClient.reconnect();
}
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