Google Play UI Exit Detection

My game currently uses the menu entry and exit buttons to use Google Play / Achievements ratings. Unfortunately, the user can also exit the Google Play user interface, but GameHelper.isSignedIn () still returns true when they do this through the Google user interface. When a user tries to check the leaderboard or achievement after the user selects this method, the game will crash.

Does anyone know an updated way to check if a user is being called through an interface? I am saying update as I have seen several threads in stackoverflow that do not work.

+4
source share
2 answers

I just followed https://developers.google.com/games/services/training/signin and everything works fine. He uses

boolean mExplicitSignOut = false;
boolean mInSignInFlow = false; // set to true when you're in the middle of the
                           // sign in flow, to know you should not attempt
                           // to connect in onStart()
GoogleApiClient mGoogleApiClient;  // initialized in onCreate

@Override
protected void onStart() {
   super.onStart();
   if (!mInSignInFlow && !mExplicitSignOut) {
    // auto sign in
    mGoogleApiClient.connect();
   }
}

@Override
public void onClick (View view) {
if (view.getId() == R.id.sign_out_button) {
    // user explicitly signed out, so turn off auto sign in
    mExplicitSignOut = true;
    if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
        Games.signOut(mGoogleApiClient);
        mGoogleApiClient.disconnect();
    }
}
}
+1
source

I create an achievement called Sign in Play Games and try to unlock it onSingIn ().

@Override
public boolean unlockAchievements() {
    boolean r = true;

    if (gameHelper.isSignedIn()){
        try{
            Games.Achievements.unlock(gameHelper.getApiClient(), getString(R.string.achievement_sign_in_play_games));
        }
        catch(Exception ex){
            r = false; 
        }
        finally{
        }
    }
    else{
        r = false;
    }

    return r;
}

In case of resizing the screen on the screen where my login button is located, I will implement this code:

@Override
    public void resize(int width, int height) {

        //...

        if(game.gameHelper.isSignedIn()){
            if (!game.gameHelper.unlockAchievements()){
                game.gameHelper.forceSignOut();
            }
        }

    }

ForceSignOut () was implemented in the GameHelper class

public void forceSignOut() {
    if (mGoogleApiClient != null){
        mGoogleApiClient.disconnect();
    }
}

And finally, in BaseGameActivity:

protected void forceSignOut(){
    mHelper.forceSignOut();
}

Remember to implement your GameServiceInterface:

public void forceSignOut();
0
source

All Articles