iappmaker
iappmaker

Reputation: 3005

Listener for Leaderboard in Google game services

I have setup leaderboard using the google game services. I am using the following statement for submitting the statistics after finishing the game.

Games.Leaderboards.submitScore(mHelper.getApiClient(),leaderBoardIdForHits,
totalChanceTaken);

Question :

There may be situation that there will not be the internet services or some failure during the execution of the above submit statement. Also on successful submit of the statistics I need to show a Toast like "Statistics updated". I would like to know if there is any listener method for this.

Upvotes: 5

Views: 1502

Answers (1)

Ogen
Ogen

Reputation: 6709

Define this class:

class myLeaderBoardSubmitScoreCallback implements ResultCallback<SubmitScoreResult> {
            @Override
            public void onResult(SubmitScoreResult res) {
                if (res.getStatus().getStatusCode() == 0) {
                    // data sent successfully to server.
                    // display toast.
                }
            }
        }

Then submit your score like this:

Games.Leaderboards.submitScoreImmediate(mHelper.getApiClient(),leaderBoardIdForHits,
totalChanceTaken).setResultCallback(new myLeaderBoardSubmitScoreCallback());

So know when you submit a score, a ResultCallback is set, which is delivered when a leaderboard score has been submitted. And if it has been successfully delivered to the server, display your toast.

Upvotes: 5

Related Questions