I integrated google games services in my game, including Leaderboards and achievements. If the user opens the leaderboard or achievement activity, he has the possibility to sign out from the settings in the right upper corner.
How can I check if the user is actually signed in? getGamesClient.isConnected() is still true, although the user logged out from the google view.
If I'm clicking the logout button (which is still there, becaus gamesClient is still connected) I get an SecurityException:
08-16 11:01:21.262 14288-14288/? E/AndroidRuntime: FATAL EXCEPTION: main java.lang.SecurityException at android.os.Parcel.readException(Parcel.java:1425) at android.os.Parcel.readException(Parcel.java:1379) at com.google.android.gms.internal.bm$a$a.a(Unknown Source) at com.google.android.gms.internal.bj.signOut(Unknown Source) at com.google.android.gms.games.GamesClient.signOut(Unknown Source)
At the moment, I am checking the ActivityForResult response code and disconnecting the GamesClient, if it's in inconsistent state, but I don't like that approach.
Try handling onActivityResult:
public boolean onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == RC_YOUR_UNIQUE_ID
&& resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
mHelper.disconnect();
// update your logic here (show login btn, hide logout btn).
} else {
mHelper.onActivityResult(requestCode, resultCode, data);
}
return false;
}
RC_YOUR_UNIQUE_ID is id you've used for showing Leaderboard or Achievements activity.