借助 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);}