GamesClient not connecting. Error: “Call connect() and wait for onConnected() to be called.”

前端 未结 2 908
自闭症患者
自闭症患者 2021-01-13 18:43

I am trying to use GamesClient to use the leaderboards of the Google Play Game Services. Right now I have it so when the importbutton is clicked,

相关标签:
2条回答
  • 2021-01-13 18:52

    You are trying to submit the scores before a connection is established.

    Like the error says, you should wait for onConnected() and only then you should allow the score submission. Example: you should only show the button after it is connected

    If you are extending BaseGameActivity, you should do something like this:

    int isGooglePlayServiceAvilable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if (isGooglePlayServiceAvilable == ConnectionResult.SUCCESS) {
        beginUserInitiatedSignIn();
    } else {
        GooglePlayServicesUtil.getErrorDialog(isGooglePlayServiceAvilable, MainMenu.this, REQUEST_DIALOG).show();
    }
    

    And then, you should override these methods:

    @Override
    public void onSignInSucceeded() {
       super.onSignInSucceeded();
       // allow to submit scores
    }
    
    @Override
    public void onSignInFailed() {
        super.onSignInFailed();
        // do not allow to submit scores
    }
    
    0 讨论(0)
  • 2021-01-13 19:05

    If you are using BaseGameActivity, don't call GamesClient.connect(). The advantage of using BaseGameActivity is that it handles all the connection boilerplate for you. All you have to do is override onSignInSucceeded and make your API calls from there. Don't make any games API calls before you get onSignInSucceeded.

    Also, remember that when your activity gets an onStop, the games API will be disconnected. After that, when it subsequently gets an onStart, you would again wait for onSignInSucceeded before making any API calls.

    0 讨论(0)
提交回复
热议问题