Question

I'm currently implementing a game for Android using the Google Games api to support leaderboards. I'm also using the GameHelper class from basegameutils.

This is my code in the MainActivity:

public class MainActivity extends AndroidApplication implements GameHelperListener {

    private Game game;

    private GameHelper mHelper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mHelper = new GameHelper(this, GameHelper.CLIENT_ALL);

        mHelper.setConnectOnStart(true);

        mHelper.setup(this);

        // ...
    }

    @Override
    public void onStart() {
        super.onStart();
        mHelper.onStart(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        mHelper.onStop();
    }

    @Override
    public void onSignInSucceeded() {
        showToast("sign in succeeded");
    }

    @Override
    public void onSignInFailed() {
        showToast("sign in failed");
    }
}

When I start the app it shows the Google Play Games sign-in overlay. This dissappears after a moment. The problem is, that I'm not signed in and the client is in connecting mode all the time. Only when I close and reopen the app I see the popup, that says I'm signed in and onSignInSucceeded() is called.

Another problem is, that if I open the app with Wi-Fi turned off (same when I cancel the sign-in manually) it's not calling onSignInFailed(). As well the client is continuosly in connecting mode.

Can someone please help me to resolve the problem? Thanks in advance.

Était-ce utile?

La solution

You need to implement the onActivityResult method so that helper class knows the result returned by the sign-in activity.

It should look something as follows:

@Override
public void onActivityResult(int requestCode, int responseCode, Intent intent) {
   super.onActivityResult( requestCode, responseCode, intent );
   mHelper.onActivityResult( requestCode, responseCode, intent );
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top