With Game State API, you can let the system know what the game is currently
doing (for example: loading levels, intense networked gameplay, rendering
in-game menu, showing ads, etc). With this valuable information, the system is
be able to optimize resources and power accordingly.
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);}
Check out the modes you can notify the system in the documentation
Summary.
It is possible that the list will grow when different resource consumption
patterns is discovered in the future.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-02-28 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-02-28 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."]]