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);
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.
To create a leaderboard for a new and unpublished game, go to the Google Play Console entry for your game, and navigate to Grow > Play Games Services > Setup and management > Leaderboards, then click the Create leaderboard button.
The term leaderboard is often used in the video gaming industry to signify rank among people who play various titles. Players can be ranked against other players based on their number of kills (most common), items collected, or some other metric.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With