Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signout from google play Game service Leaderboard screen

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,

Issue.

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();
}

Question.

How do the program knows that the user has signed-out in the leaderboard screen.

like image 623
iappmaker Avatar asked Feb 09 '23 14:02

iappmaker


2 Answers

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();
    }
}
like image 54
ThomasDC Avatar answered Mar 07 '23 22:03

ThomasDC


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();

   }
like image 35
Clayton Wilkinson Avatar answered Mar 07 '23 20:03

Clayton Wilkinson