GameActivity یک کتابخانه Jetpack است که برای کمک به بازی های اندروید در پردازش دستورات چرخه برنامه، رویدادهای ورودی و ورودی متن در کد C/C++ برنامه طراحی شده است. GameActivity از نسل مستقیم NativeActivity است و معماری مشابهی دارد:
همانطور که در نمودار بالا نشان داده شده است، GameActivity عملکردهای زیر را انجام می دهد:
تعامل با فریم ورک اندروید از طریق کامپوننت جاوا.
ارسال دستورات چرخه برنامه، رویدادهای ورودی و متن ورودی به سمت اصلی.
مدل سازی کد منبع C/C++ به سه جزء منطقی:
توابع JNI GameActivity که مستقیماً از عملکرد جاوا GameActivity پشتیبانی می کند و رویدادها را در native_app_glue قرار می دهد.
native_app_glue ، که بیشتر در رشته اصلی خود (متفاوت از رشته اصلی برنامه) اجرا می شود و وظایف را با حلقه خود اجرا می کند.
کد بازی برنامه، که رویدادهای ردیف شده در داخل native_app_glue نظرسنجی و پردازش می کند و کد بازی را در رشته native_app_glue اجرا می کند.
با GameActivity ، می توانید بر روی توسعه بازی اصلی خود تمرکز کنید و از صرف زمان زیاد برای مقابله با کد JNI خودداری کنید.
اگر قبلاً با NativeActivity آشنا هستید، تفاوت های عمده بین GameActivity و NativeActivity به شرح زیر است:
GameActivity به SurfaceView تبدیل می شود و تعامل بازی ها با سایر اجزای رابط کاربری را بسیار آسان تر می کند.
برای رویدادهای ورودی لمسی و کلیدی، GameActivity یک پیاده سازی کاملاً جدید با رابط android_input_buffer دارد، جدا از InputQueue که NativeActivity استفاده می کند.
GameActivity یک کلاس مشتق شده از AppCompatActivity است که به شما امکان می دهد به طور یکپارچه از سایر اجزای Jetpack استفاده کنید. ActionBar ، Fragment و موارد دیگر همگی در دسترس هستند.
برنامه های مشتق شده از GameActivity انتظار می رود هر سه بخش کد C/C++ را در یک کتابخانه بسازند. از سوی دیگر، توابع JNI NativeActivity بخشی از چارچوب هستند (همیشه توسط سیستم عامل بارگذاری می شوند). از این رو، انتظار می رود که فقط native_app_glue و کد C/C++ برنامه در یک کتابخانه ساخته شوند.
NativeActivity بخشی از چارچوب اندروید است و از چرخه انتشار آن (معمولا سالانه) پیروی می کند. GameActivity بخشی از کتابخانه Jetpack است که چرخه انتشار بسیار بیشتری دارد (معمولاً هر دو هفته). ویژگیهای جدید و رفع اشکال میتوانند خیلی سریعتر وارد شوند.
کد C/C++ به عنوان کد منبع در همه کانالهای انتشار با استفاده از قالب Prefab ارائه میشود. GameActivity نسخه 1.2.2 یک کتابخانه ثابت به توزیع اضافه می کند. با شروع با این نسخه و نسخه های بعدی، توصیه می کنیم به جای کد منبع از کتابخانه ایستا استفاده کنید.
محتویات کتابخانه Jetpack و بسته فشرده AGDK
با کتابخانه Jetpack و کانال های بسته فشرده AGDK، GameActivity با AAR منتشر می شود. این AAR شامل اجزای اصلی زیر است:
یک فایل JAR برای کد جاوا
کتابخانه استاتیک C/C++ game-activity_static همراه با GameActivity نسخه 1.2.2 و جدیدتر موجود است.
کد منبع C/C++ (در زیر پوشه /prefab )
دستورالعملهای یکپارچهسازی مرتبط با این صفحه فرض میکنند که میتوانید از Prefab در سیستم ساخت خود استفاده کنید. در غیر این صورت، می توانید کد منبع بسته بندی شده در پوشه prefab/modules/game-activity/include در سیستم ساخت خود کپی کنید و مراحل یکپارچه سازی لازم را انجام دهید. ساختار فایل مشابهی برای نسخه های تحت androidx برای کتابخانه Android Jetpack وجود دارد. به طور پیش فرض، gradle AAR ها را در فهرست کش خود باز می کند (~/.gradle/caches/...). می توانید کد منبع C/C++ را با جستجوی prefab/modules/game-activity/include و انتخاب مکان تحت نسخه نسخه مورد نظر خود بیابید.
برای دستورالعملهای مربوط به ادغام با استفاده از کتابخانه Jetpack، به شروع با GameActivity مراجعه کنید.
محتوای کد منبع AOSP
AOSP همیشه حاوی جدیدترین کد منبع است. دستورالعمل های ساخت را دنبال کنید تا نسخه های خود را ایجاد کنید یا منبع را مستقیماً در محیط ساخت خود ادغام کنید. کد منبع C/C++ در یک ساختار فایل شبیه به آنهایی که برای کتابخانه Jetpack و بسته فشرده AGDK ذخیره می شود.
راهنمای ادغام
برای ادغام GameActivity در برنامه های خود این راهنماها را دنبال کنید:
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-26 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-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)."]]