[[["容易理解","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-27 (世界標準時間)。"],[],[],null,["# Optimize refresh rates\n\n[Android 15](/about/versions/15) sets a default 60Hz refresh rate for games to optimize\npower consumption. To unlock higher frame rates like 120 FPS, you must now\nexplicitly request them using the [Frame Rate API](/media/optimize/performance/frame-rate) or the Swappy\nlibrary.\n\nHowever, the system may override this request based on factors like battery\nlevel or device temperature. While higher refresh rates enhance visual\nsmoothness, they also demand more power and generate additional heat. Therefore,\nit's crucial to offer users the option to choose their preferred refresh rate\nand carefully monitor performance to ensure a balanced user experience.\n\nUse the [`setFrameRate()`](/reference/android/view/Surface#setFrameRate(float,%20int)) API\n------------------------------------------------------------------------------------------\n\nThe [`setFrameRate()`](/reference/android/view/Surface#setFrameRate(float,%20int)) API allows the game devs to use a specific display\nrefresh rate. There are two steps to doing this:\n\n1. Verify device and Android version compatibility.\n2. Request high FPS using [`setFrameRate()`](/reference/android/view/Surface#setFrameRate(float,%20int)).\n\n### Verify Device and Android Version Compatibility:\n\nUse methods [`Display.getSupportedModes()`](/reference/android/view/Display#getSupportedModes()) to determine if the device\nsupports 90Hz, 120Hz, or other refresh rates. If the device is limited to 60Hz,\nit is not possible to exceed this limit. \n\n### Kotlin\n\n val display = windowManager.defaultDisplay\n val supportedModes = display.supportedModes\n for (mode in supportedModes) {\n Log.d(\"DisplayInfo\", \"Supported mode: ${mode.physicalWidth}x${mode.physicalHeight}, ${mode.refreshRate}Hz\")\n }\n\n### Request High FPS\n\nInvoke [`setFrameRate()`](/reference/android/view/Surface#setFrameRate(float,%20int)) when your rendering loop starts, during game window\ninitialization, or when the target FPS needs to change the display refresh rate.\n\nEven if you request a higher rate, the system might still limit the refresh rate\nto 60Hz due to factors like power saving mode or thermal throttling. If your\ngame's rendering performance doesn't reach the target FPS, requesting higher\nrefresh rate may consume unnecessary power consumption and increase the device's\ntemperature.\n\nThe following snippet demonstrates how to avoid an overly high refresh rate with\nthe `setFrameRate()` API. \n\n### Kotlin\n\n val targetFps = 120f\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.R) {\n window.setFrameRate(\n targetFps,\n Window.FrameRateCompatibility.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE,\n 0\n )\n }\n\n[The Framerate page](/media/optimize/performance/frame-rate) provides more detailed information for further reading.\n\nUse Frame pacing library\n------------------------\n\n[The frame pacing library](/media/optimize/performance/frame-rate), or Swappy, is an open-source library designed to\nsimplify [VSync](https://en.wikipedia.org/wiki/Vertical_blanking_interval) management and frame scheduling in C/C++ Android game\nengines.\nThis tool streamlines the process of optimizing refresh rates, effectively\nacting as a higher-level abstraction layer over functionalities like\n[`setFrameRate()`](/reference/android/view/Surface#setFrameRate(float,%20int)). Furthermore, Swappy provides additional features that can\nenhance your game's overall smoothness and performance.\n\n[The Swappy page](/media/optimize/performance/frame-rate) gives more detailed information.\n\nAdditional Tips for Best Results\n--------------------------------\n\nThe following section lay out several top tips:\n\n1. Dynamic Frame Rate Switching.\n2. Performance Monitoring.\n3. Provide FPS options based on maximum display refresh rate.\n\n### Dynamic Frame Rate Switching\n\nTo optimize both performance and power consumption, consider implementing\ndynamic frame rate switching in your game. This technique lets you\nseamlessly transition between higher refresh rates like 120Hz for smoother\ngameplay during demanding scenes, and lower rates like 60Hz during less\nintensive moments or when battery life is a concern or targeting under 60FPS.\nConstantly running at 120Hz can lead to excessive\n[heat generation](/games/optimize/adpf/thermal) and rapid battery drain, potentially resulting in a\nnegative user experience. By intelligently adjusting the refresh rate based on\nthe current rendering load and device conditions, you can strike a balance\nbetween visual fidelity and [power efficiency](/games/optimize/power).\n\n### Performance Monitoring\n\nTo ensure your game performs optimally at higher refresh rates, integrate\nperformance monitoring tools such as a frame counter or performance overlay.\nThese tools provide real-time feedback on your game's actual frame rate,\nallowing you to verify whether you're consistently achieving the target 120\nFPS.\n\nIf your frame rate fluctuates significantly, consider targeting a lower\nachievable framerate on the given device. This can deliver a smoother experience\nwithout the performance hiccups that might occur when striving for the highest\nrefresh rate.\n\n### Provide FPS options based on maximum display refresh rate\n\nYour game should detect the maximum display refresh rate supported by the\ncurrent device, such as 60Hz, 90Hz, or 120Hz, and limit the FPS settings\naccordingly. For example, if the device only supports up to 60Hz, it is\nadvisable to disable any options higher than 60FPS in the game settings to\navoid confusing the player."]]