StateFlowleaderboards/ directory. Open the project in Android Studio and configure your application ID in MainActivity.kt by replacing the APPLICATION_ID property getter. For detailed build instructions, see the repository README.| File | What it demonstrates | Key concepts |
|---|---|---|
Service connection and UI layout | HorizonServiceConnection setup, two-column Compose layout with controls and output | |
All five leaderboard API methods | Read operations ( get, getEntries, getEntriesByIds), write operations (writeEntry, writeEntryWithSupplementaryMetric), pagination handling |
sample_leaderboard_visible), preset buttons for switching between leaderboards, a score stepper for adjusting values, and buttons for each of the five SDK methods. The right column displays operation results as formatted text or error messages.HorizonServiceConnection.connect(
APPLICATION_ID,
this@MainActivity.applicationContext,
lifecycleScope,
)
MainActivity.kt.get() retrieves leaderboard definitions with metadatagetEntries() fetches ranked entries with scores and user IDsgetEntriesByIds() queries entries for specific user IDsfetchInitialPage() followed by getFetchedPages().leaderboards.writeEntry(name, score, null, null)
writeEntry() submits a score to a leaderboard. writeEntryWithSupplementaryMetric() adds a supplementary metric alongside the primary score.fetchInitialPage() on the paged results object, retrieve the fetched pages collection, and extract the first page’s contents. The sample only processes the initial page — multi-page iteration is not demonstrated.getEntriesByIds() with a custom selection UI.