2K 利用 Android Game Development Kit 将 ANR 发生率降低了 35%
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
背景

Cat Daddy Games 是一家全资 2K 工作室,位于华盛顿州柯克兰,是 NBA 2K Mobile 的开发者。该团队希望提高游戏的整体质量和稳定性,具体方法是减少“应用无响应”错误 (ANR)。如果 Android 应用的界面线程处于阻塞状态的时间过长,就会发生 ANR。发生这种情况时,负责更新界面的应用主线程将无法绘制或处理用户输入事件,这会引起用户的不满。如果应用在前台运行,系统会显示一个对话框,允许用户强制退出应用。
策略
减少 ANR 一直是 Cat Daddy 的首要任务。QA 团队坚持不懈,最终确定了一种常见的 ANR 模式:他们发现,当应用暂停然后快速恢复时,大量触控输入可能会导致 ANR。我们对 Firebase Crashlytics 进行的进一步调查表明,此 ANR 的类型为 android.os.MessageQueue.nativePollOnce,这是 NBA 2K Mobile 中最常见的 ANR 类型。
Cat Daddy 还发现 GameActivity 中经过改进的输入处理功能可以避免此类 ANR,因此他们决定改用 GameActivity。
GameActivity 是 Android Game Development Kit 的一个组件,旨在协助 Android 游戏在应用的 C/C++ 代码中处理应用周期命令、输入事件和文本输入。与 NativeActivity
相比,GameActivity 提供了多项以游戏为中心的改进,例如 Fragment
、渲染到 SurfaceView
,以及对与游戏开发相关的热门库的其他支持。
GameActivity 还在其输入缓冲区中使用双重缓冲,从而使游戏可以更好地处理这种高输入量的情况。
成果
通过实现 GameActivity,Cat Daddy 显著提升了游戏的输入处理能力,从而使 ANR 错误减少了 35%。这改善了用户体验并打造了更稳定的游戏体验。
此外,由于 GameActivity 继承自 FragmentActivity
,因此 CatDaddy 还能够集成 EmbeddedWebView 和 EmbeddedVideoView,而这是一些最热门的社交游戏集成所必需的。
开始使用
借助 GameActivity 和 Android Game Development Kit 的其余部分,提升您自己的游戏体验。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2022-12-09。
[null,null,["最后更新时间 (UTC):2022-12-09。"],[],[],null,["# 2K reduces ANR rate by 35% with the Android Game Development Kit\n\nBackground\n----------\n\nCat Daddy Games is a wholly-owned\n[2K](https://play.google.com/store/apps/dev?id=6681606924556273560)\nstudio based in Kirkland, Washington and the developer of NBA 2K Mobile.\nThe team wanted to improve the overall quality and stability of their games,\nspecifically by reducing \"Application Not Responding\" errors (ANRs). ANRs\noccur when the UI thread of an Android app is blocked for too long. When\nthat happens, the app's main thread, which is responsible for updating the\nUI, can't draw or process user input events, causing frustration to the user.\nIf the app is running in the foreground, the system displays a dialog that\nallows the user to force-quit the app.\n\nWhat they did\n-------------\n\nReducing ANRs has been a high priority for Cat Daddy. The QA team worked\nrelentlessly and nailed down a common ANR pattern: they found that when the app\nwas paused and then quickly resumed, a large amount of touch input could cause\nan ANR. Further investigation with\n[Firebase Crashlytics](https://firebase.google.com/docs/crashlytics) showed\nthat this ANR was of type android.os.MessageQueue.nativePollOnce, the most\ncommon type of ANR for NBA 2K Mobile.\n\nCat Daddy also saw that the improved input handling in GameActivity could avoid\nthis type of ANRs, so they decided to move to GameActivity.\n\n[GameActivity](/games/agdk/game-activity) is a component of the\n[Android Game Development Kit](/stories/games/games/agdk), which\nis designed to assist Android games in processing app cycle commands, input\nevents, and text input in the application's C/C++ code. GameActivity offers a\nnumber of game-focused improvements over `NativeActivity`, such as\n[`Fragment`](/reference/androidx/fragment/app/Fragment), rendering to a\n[`SurfaceView`](/reference/android/view/SurfaceView), and other support\nfor popular game development-related libraries.\n\nGameActivity also uses double buffering in its input buffer, allowing the game\nto better handle this case of high input volume.\n\nResults\n-------\n\nBy implementing GameActivity, Cat Daddy was able to significantly improve the\ninput handling of the game, leading to a 35% reduction in ANR errors. This\nimproved the user experience and created a more stable gameplay experience.\n\nAs an added bonus, because GameActivity inherits from\n[`FragmentActivity`](/reference/androidx/fragment/app/FragmentActivity),\nCatDaddy was also able to integrate EmbeddedWebView and EmbeddedVideoView,\nwhich were required for some of the most popular social game integrations.\n\nGet started\n-----------\n\nImprove your own game experience with [GameActivity](/games/agdk/game-activity)\nand the rest of the [Android Game Development Kit](/games/agdk)."]]