[null,null,["最后更新时间 (UTC):2025-08-26。"],[],[],null,["GameActivity\nPart of [Android Game Development Kit](/games/agdk/overview).\n\n[`GameActivity`](/reference/games/game-activity) is a Jetpack library designed\nto assist Android games in processing app cycle commands, input events, and text\ninput in the application's C/C++ code. `GameActivity` is a direct descendant of\n[`NativeActivity`](/reference/android/app/NativeActivity) and shares a similar\narchitecture:\n\nAs illustrated in the above diagram, `GameActivity` performs the following\nfunctions:\n\n- Interacting with Android framework through the Java-side component.\n- Passing app cycle commands, input events, and input text to the native side.\n- Modelling C/C++ source code into three logical components:\n - GameActivity's JNI functions, which directly support GameActivity's Java functionality and enqueue the events to `native_app_glue`.\n - `native_app_glue`, which runs mostly in its own native thread (different from the application's main thread), and executes tasks with its looper.\n - The application's game code, which polls and processes the events queued inside `native_app_glue` and executes game code within the `native_app_glue` thread.\n\nWith `GameActivity`, you can focus on your core game development and avoid\nspending excessive time dealing with the JNI code.\n\nIf you are already familiar with `NativeActivity`, the major differences\nbetween `GameActivity` and `NativeActivity` are as follows:\n\n- `GameActivity` renders into a [`SurfaceView`](/reference/android/view/SurfaceView), making it much easier for games to interact with other UI components.\n- For touch and key input events, `GameActivity` has a completely new implementation with the [`android_input_buffer`](/reference/games/game-activity/structandroid/input-buffer) interface, separate from the [`InputQueue`](/reference/android/view/InputQueue) that `NativeActivity` uses.\n- `GameActivity` is a derived class of `AppCompatActivity`, which lets you seamlessly use other Jetpack components. [`ActionBar`](/reference/android/app/ActionBar), [`Fragment`](/guide/fragments), and others are all available.\n- `GameActivity` adds text input functionality by integrating [the\n GameTextInput library](/games/agdk/add-support-for-text-input).\n- Apps derived from `GameActivity` are expected to build all three parts of C/C++ code into one library. On the other hand, `NativeActivity`'s JNI functions are a part of the framework (always loaded by OS). Hence, only the `native_app_glue` and application's C/C++ code are expected to be built into one library.\n- `NativeActivity` is a part of Android framework and follows its release cycle (typically yearly). `GameActivity` is a part of the Jetpack library, which has a much more frequent release cycle (typically biweekly); new features and bug fixes can arrive much more quickly.\n\n| **Note:** We strongly recommend using `GameActivity` for new games and other C/C++ intensive applications. If you have an existing `NativeActivity` application, we recommend migrating to `GameActivity`.\n\nRelease locations\n\nThe `GameActivity` library is available in the following channels:\n\n- As a part of the [Android Jetpack library](/jetpack/androidx/releases/games) (recommended)\n- As [AOSP](https://android.googlesource.com/platform/frameworks/opt/gamesdk/) source code\n\nThe C/C++ code is provided as source code in all release channels, using the\n[Prefab](/studio/build/dependencies?agpversion=4.0#native-dependencies-aars)\nformat. GameActivity version 1.2.2 adds a static library to the distribution.\nStarting with this version and later, we recommend you use the static library\ninstead of the source code.\n| **Note:** Most of the documentation on this site is written from the perspective of AndroidX.\n\nContents of Jetpack library and AGDK zip package\n\nWith the Jetpack library and AGDK zip package channels, GameActivity is released\nwith an AAR. This AAR contains the following major components:\n\n- A JAR file for Java code\n- The C/C++static library `game-activity_static` is included with GameActivity version 1.2.2 and later.\n- C/C++ source code (under the `/prefab` folder)\n\nThe integration instructions linked to from this page assume that you can use\nPrefab in your build system; otherwise, you can copy the source code packed\nunder the `prefab/modules/game-activity/include` folder into your build system\nand perform the necessary integration steps. A similar file structure exists for\nthe releases under `androidx` for the Android Jetpack library; by default,\ngradle unpacks AARs in its cache directory (\\~/.gradle/caches/...). You can find\nthe C/C++ source code by searching for `prefab/modules/game-activity/include`\nand picking up the location under your intended release version.\n\nFor instructions on integrating using the Jetpack library, see\n[Get started with GameActivity](/games/agdk/game-activity/get-started).\n\nContent of AOSP source code\n\nAOSP always contains the most recent source code. Follow [the build\ninstructions](https://android.googlesource.com/platform/frameworks/opt/gamesdk/+/refs/heads/master/GameActivity/) to create your own releases or directly integrate the source into\nyour build environment. The C/C++ source code is saved in a file structure\nsimilar to the ones for the Jetpack library and AGDK zip package.\n\nIntegration guides\n\nFollow those guides to integrate `GameActivity` into your applications:\n\n- [Get started](/games/agdk/game-activity/get-started)\n- [Use game text input](/games/agdk/game-activity/use-text-input)\n- [NativeActivity migration guide](/games/agdk/game-activity/migrate-native-activity)\n\nAdditional resources\n\nTo learn more about `GameActivity`, see the following:\n\n- [GameActivity and AGDK release notes](/games/agdk/release-notes).\n- [Use GameTextInput in GameActivity](/games/agdk/game-activity/use-text-input).\n- [NativeActivity migration guide](/games/agdk/game-activity/migrate-native-activity).\n- [GameActivity reference documentation](/reference/games/game-activity/group/game-activity).\n- [GameActivity implementation](https://android.googlesource.com/platform/frameworks/opt/gamesdk/+/refs/heads/master/game-activity/).\n\nFeedback\n\nTo report bugs or request new features to GameActivity, use\n[the GameActivity issue tracker](https://issuetracker.google.com/issues/new?component=897320&template=1456805)."]]