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,
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
}
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.