Google Play Game Services

Leaderboards in Android

You can use the Play Games services APIs to create visual leaderboards, record a player's score, and compare the score against the player's score from previous game sessions.

Before your game can display or update a leaderboard, make sure that you have first created the leaderboard, as described in the Google Play Developer Console guide.

Understanding leaderboards

If you haven't already done so, you might find it helpful to review the leaderboards game concepts..

Updating the player's score

When the player's score changes (for example, when the player finishes the game), your game can update their score on the leaderboard by calling submitScore(), and passing in the leaderboard ID and the raw score value.

Games.Leaderboards.submitScore(getApiClient(), LEADERBOARD_ID, 1337);

A good practice is to define the leaderboard ID in your strings.xml file, so your game can reference the leaderboards by resource ID. When making calls to update and load player scores, make sure to also follow these best practices for to avoid exceeding your API quota.

Displaying a leaderboard

To display a leaderboard, call the startActivityForResult and pass in the intent to create the default leaderboard UI. In the following code snippet, REQUEST_LEADERBOARD is an arbitrary integer for the request code.

startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), LEADERBOARD_ID), REQUEST_LEADERBOARD);

Notice that even though no result is returned, we have to use startActivityForResult so that the API can obtain the identity of the calling package. An example of the default leaderboard UI is shown below.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.