সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
ভিজ্যুয়াল লিডারবোর্ড তৈরি করতে, প্লেয়ারের স্কোর রেকর্ড করতে এবং আগের গেম সেশন থেকে প্লেয়ারের স্কোরের সাথে স্কোর তুলনা করতে এই গাইডটি আপনাকে দেখায় কিভাবে একটি Android অ্যাপে লিডারবোর্ড API ব্যবহার করতে হয়। API গুলি com.google.android.gms.games এবং com.google.android.gms.games.leaderboards প্যাকেজে পাওয়া যাবে৷
যখন প্লেয়ারের স্কোর পরিবর্তিত হয় (উদাহরণস্বরূপ, খেলোয়াড় যখন গেমটি শেষ করে), তখন আপনার গেমটি লিডারবোর্ডে তাদের স্কোর আপডেট করতে পারে LeaderboardsClient.submitScore() এ কল করে এবং লিডারবোর্ড আইডি এবং কাঁচা স্কোর মান পাস করে।
একটি ভাল অভ্যাস হল আপনার strings.xml ফাইলে লিডারবোর্ড আইডি সংজ্ঞায়িত করা, যাতে আপনার গেম রিসোর্স আইডি দ্বারা লিডারবোর্ড উল্লেখ করতে পারে। প্লেয়ার স্কোর আপডেট এবং লোড করার জন্য কল করার সময়, আপনার API কোটা অতিক্রম না করার জন্য এই সর্বোত্তম অনুশীলনগুলি অনুসরণ করতে ভুলবেন না।
নিম্নলিখিত কোড স্নিপেট দেখায় কিভাবে আপনার অ্যাপ প্লেয়ারের স্কোর আপডেট করতে পারে। কোড স্নিপেটে, RC_LEADERBOARD_UI হল অনুরোধ কোডের জন্য একটি নির্বিচারে পূর্ণসংখ্যা।
যদিও কোন ফলাফল ফেরত না আসে, আপনাকে startActivityForResult ব্যবহার করতে হবে যাতে API কলিং প্যাকেজের পরিচয় পেতে পারে। ডিফল্ট লিডারবোর্ড UI এর একটি উদাহরণ নীচে দেখানো হয়েছে।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Leaderboards in Android games\n\n| **Note:** This guide is for the Play Games Services v2 SDK. For information on the previous version of this SDK, see the [Play Games Services v1\n| documentation](/games/pgs/v1/android/leaderboards).\n\nThis guide shows you how to use leaderboards APIs in an Android app\nto create visual leaderboards, record a player's score, and compare the score\nagainst the player's score from previous game sessions. The APIs can be found\nin the [`com.google.android.gms.games`](https://developers.google.com/android/reference/com/google/android/gms/games/package-summary)\nand [`com.google.android.gms.games.leaderboards`](https://developers.google.com/android/reference/com/google/android/gms/games/leaderboard/package-summary) packages.\n\nBefore you begin\n----------------\n\nIf you haven't already done so, you might find it helpful to review the\n[leaderboards game concepts](/games/pgs/leaderboards).\n\nBefore you start to code using the leaderboards APIs:\n\n- Follow the instructions for installing and setting up your app to use\n Google Play Games Services in the\n [Set Up Google Play Services SDK](https://developers.google.com/android/guides/setup) guide.\n\n- Define the leaderboards that you want your game to display or update, by\n following the instructions in the\n [Google Play Console guide](/games/pgs/leaderboards#creating_a_leaderboard).\n\n- Download and review the leaderboards code samples in the\n [Android samples page](https://github.com/playgameservices/android-basic-samples) on GiHub.\n\n- Familiarize yourself with the recommendations described in\n [Quality Checklist](/games/pgs/quality).\n\nGet the leaderboards client\n---------------------------\n\nTo start using the leaderboards API, your game must first obtain a\n[`LeaderboardsClient`](https://developers.google.com/android/reference/com/google/android/gms/games/LeaderboardsClient) object.\nYou can do this by calling the [`PlayGames.getLeadeboardsClient()`](https://developers.google.com/android/reference/com/google/android/gms/games/PlayGames#public-static-leaderboardsclient-getleaderboardsclient-activity-activity)\nmethod and passing in the activity.\n| **Note:** The [`LeaderboardsClient`](https://developers.google.com/android/reference/com/google/android/gms/games/LeaderboardsClient) class makes use of the Google Play services Task class to return results asynchronously. To learn more about using tasks to manage threaded work, see the [Tasks API developer guide](https://developers.google.com/android/guides/tasks).\n\nUpdate the player's score\n-------------------------\n\nWhen the player's score changes (for example, when the player finishes the game), your\ngame can update their score on the leaderboard by calling\n[`LeaderboardsClient.submitScore()`](https://developers.google.com/android/reference/com/google/android/gms/games/LeaderboardsClient#submitScore),\nand passing in the leaderboard ID and the raw score value.\n\nThe following code snippet shows how your app can update the player's score: \n\n```scdoc\nPlayGames.getLeaderboardsClient(this)\n .submitScore(getString(R.string.leaderboard_id), 1337);\n```\n\nA good practice is to define the leaderboard ID in your `strings.xml` file, so\nyour game can reference the leaderboards by resource ID. When making calls to\nupdate and load player scores, make sure to also follow these\n[best practices](/games/pgs/quality) to avoid exceeding your API quota.\n\nDisplay a leaderboard\n---------------------\n\nTo display leaderboard, call\n[`LeaderboardsClient.getLeaderboardIntent()`](https://developers.google.com/android/reference/com/google/android/gms/games/LeaderboardsClient#getLeaderboardIntent(java.lang.String)) to get an\n[`Intent`](/reference/android/content/Intent) to\ncreate the default leaderboard user interface. Your game can then bring up the\nUI by calling\n[`startActivityForResult`](/reference/android/app/Activity#startActivityForResult).\n\nThe following code snippet shows how your app can update the player's score. In the\ncode snippet, `RC_LEADERBOARD_UI` is an arbitrary integer for the request code. \n\n```transact-sql\nprivate static final int RC_LEADERBOARD_UI = 9004;\n\nprivate void showLeaderboard() {\n PlayGames.getLeaderboardsClient(this)\n .getLeaderboardIntent(getString(R.string.leaderboard_id))\n .addOnSuccessListener(new OnSuccessListener\u003cIntent\u003e() {\n @Override\n public void onSuccess(Intent intent) {\n startActivityForResult(intent, RC_LEADERBOARD_UI);\n }\n });\n}\n```\n\nEven though no result is returned, you have to use\n[`startActivityForResult`](/reference/android/app/Activity#startActivityForResult)\nso that the API can obtain the identity of the calling package. An example of\nthe default leaderboard UI is shown below."]]