ด้วย Game State API คุณสามารถบอกให้ระบบรู้ว่าเกมคืออะไร
(เช่น ระดับการโหลด เกมเพลย์ที่ดำเนินเป็นเครือข่ายอย่างหนัก การแสดงภาพ
เมนูในเกม การแสดงโฆษณา เป็นต้น) ด้วยข้อมูลที่มีประโยชน์นี้ ระบบจึง
สามารถใช้ทรัพยากรและเพิ่มประสิทธิภาพในการทำงานได้อย่างเหมาะสม
Java
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S){// Get GameManager from SystemServiceGameManagergameManager=Context.getSystemService(GameManager.class);GameStategameState=newGameState(false,GameState.MODE_GAMEPLAY_UNINTERRUPTIBLE);gameManager.setGameState(gameState);}
[[["เข้าใจง่าย","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-26 UTC"],[],[],null,["# Game State API\n\n**Released**:\n\nAndroid 13 (API Level 33) - [Java](/reference/android/app/GameState)\n\nWith Game State API, you can let the system know what the game is currently\ndoing (for example: loading levels, intense networked gameplay, rendering\nin-game menu, showing ads, etc). With this valuable information, the system is\nbe able to optimize resources and power accordingly. \n\n### Java\n\n if ( Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.S ) {\n // Get GameManager from SystemService\n GameManager gameManager =\n Context.getSystemService(GameManager.class);\n GameState gameState = new GameState(false,\n GameState.MODE_GAMEPLAY_UNINTERRUPTIBLE);\n gameManager.setGameState(gameState);\n }\n\nCheck out the modes you can notify the system in the documentation\n[Summary](/reference/android/app/GameState#summary).\nIt is possible that the list will grow when different resource consumption\npatterns is discovered in the future."]]