使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
gpg::AndroidInitialization
#include <android_initialization.h>
AndroidInitialization 包含三个初始化函数,必须调用其中一个。
摘要
对于标准 Java activity,应使用 JNI_OnLoad。对于不会调用 JNI_OnLoad 的 NativeActivity,应使用 android_main 或 ANativeActivity_onCreate。使用 android_native_app_glue.h 构建 NativeActivity 时,应使用 android_main。仅使用 native_activity.h 构建 NativeActivity 时,应使用 ANativeActivity_onCreate。android_native_app_glue.h 和 native_activity.h 是默认的 Android 头文件。
必须先调用适当的初始化函数(仅调用一次),然后才能调用任何 AndroidPlatformConfiguration 实例方法,并且必须先调用该函数,然后才能实例化 GameServices 对象。允许在某个初始化调用之前实例化 AndroidPlatformConfiguration(例如,如果配置对象具有全局作用域),前提是初始化调用之前未调用任何方法。在调用程序的生命周期内,只需调用一次这些方法,而不是在每次创建 GameServices 对象时调用一次。
公共静态函数
|
ANativeActivity_onCreate(ANativeActivity *native_activity, void *savedState, size_t savedStateSize)
|
void
将 Play 游戏服务与仅基于 native_activity.h 的 NativeActivity 搭配使用时,应在 activity 的 ANativeActivity_onCreate 期间调用 ANativeActivity_onCreate,在任何其他 Play 游戏服务调用之前。
|
JNI_OnLoad(JavaVM *jvm)
|
void
将 Play 游戏服务与标准 Java activity 搭配使用时,应在调用动态库的 JNI_OnLoad 时调用 JNI_OnLoad。
|
android_main(struct android_app *app)
|
void
将 Play 游戏服务与基于 android_native_app_glue.h 的 NativeActivity 搭配使用时,应在 activity 的 android_main 期间调用 android_main,并在任何其他 Play 游戏服务调用之前调用。
|
公共静态函数
ANativeActivity_onCreate
void gpg::AndroidInitialization::ANativeActivity_onCreate(
ANativeActivity *native_activity,
void *savedState,
size_t savedStateSize
)
将 Play 游戏服务与仅基于 native_activity.h 的 NativeActivity 搭配使用时,应在 activity 的 ANativeActivity_onCreate 期间调用 ANativeActivity_onCreate,在任何其他 Play 游戏服务调用之前。
JNI_OnLoad
void gpg::AndroidInitialization::JNI_OnLoad(
JavaVM *jvm
)
将 Play 游戏服务与标准 Java activity 搭配使用时,应在调用动态库的 JNI_OnLoad 时调用 JNI_OnLoad。
android_main
void gpg::AndroidInitialization::android_main(
struct android_app *app
)
将 Play 游戏服务与基于 android_native_app_glue.h 的 NativeActivity 搭配使用时,应在 activity 的 android_main 期间调用 android_main,并在任何其他 Play 游戏服务调用之前调用。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# gpg::AndroidInitialization Struct Reference\n\ngpg::AndroidInitialization\n==========================\n\n`#include \u003candroid_initialization.h\u003e`\n\n[AndroidInitialization](/games/services/cpp/api/struct/gpg/android-initialization#structgpg_1_1_android_initialization) includes three initialization functions, exactly one of which must be called.\n\nSummary\n-------\n\nIn the case of a standard Java Activity, JNI_OnLoad should be used. In the case of a NativeActivity where JNI_OnLoad will not be called, either android_main or ANativeActivity_onCreate should be used. android_main is used when building a NativeActivity using android_native_app_glue.h. ANativeActivity_onCreate is used when building a NativeActivity using just native_activity.h. android_native_app_glue.h and native_activity.h are default Android headers.\n\nThe appropriate initialization function must be called exactly once before any [AndroidPlatformConfiguration](/games/services/cpp/api/class/gpg/android-platform-configuration#classgpg_1_1_android_platform_configuration) instance methods are called, and it must be called before a [GameServices](/games/services/cpp/api/class/gpg/game-services#classgpg_1_1_game_services) object is instantiated. It is permitted to instantiate a [AndroidPlatformConfiguration](/games/services/cpp/api/class/gpg/android-platform-configuration#classgpg_1_1_android_platform_configuration) before one of the initialization calls (for example, if the configuration object has global scope), as long as no methods are called before the initialization call. These methods need be called only once in the lifetime of the calling program, not once per [GameServices](/games/services/cpp/api/class/gpg/game-services#classgpg_1_1_game_services) object created.\n\n| ### Public static functions ||\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [ANativeActivity_onCreate](#structgpg_1_1_android_initialization_1a816753e9576f07d1d58f2e94b26ad66c)`(ANativeActivity *native_activity, void *savedState, size_t savedStateSize)` | `void` When using Play Game Services with a NativeActivity which is based on only native_activity.h, ANativeActivity_onCreate should be called during your activity's ANativeActivity_onCreate, before any other Play Game Services calls. |\n| [JNI_OnLoad](#structgpg_1_1_android_initialization_1ae43182cd58941ddc74eb07535c8de97a)`(JavaVM *jvm)` | `void` When using Play Game Services with a standard Java Activity, JNI_OnLoad should be called when the dynamic library's JNI_OnLoad is called. |\n| [android_main](#structgpg_1_1_android_initialization_1ace2b90a82cc0b9ad5aeb7ac73996b100)`(struct android_app *app)` | `void` When using Play Game Services with a NativeActivity which is based on android_native_app_glue.h, android_main should be called during your activity's android_main, before any other Play Game Services calls. |\n\nPublic static functions\n-----------------------\n\n### ANativeActivity_onCreate\n\n```c++\nvoid gpg::AndroidInitialization::ANativeActivity_onCreate(\n ANativeActivity *native_activity,\n void *savedState,\n size_t savedStateSize\n)\n``` \nWhen using Play Game Services with a NativeActivity which is based on only native_activity.h, ANativeActivity_onCreate should be called during your activity's ANativeActivity_onCreate, before any other Play Game Services calls. \n\n### JNI_OnLoad\n\n```c++\nvoid gpg::AndroidInitialization::JNI_OnLoad(\n JavaVM *jvm\n)\n``` \nWhen using Play Game Services with a standard Java Activity, JNI_OnLoad should be called when the dynamic library's JNI_OnLoad is called. \n\n### android_main\n\n```c++\nvoid gpg::AndroidInitialization::android_main(\n struct android_app *app\n)\n``` \nWhen using Play Game Services with a NativeActivity which is based on android_native_app_glue.h, android_main should be called during your activity's android_main, before any other Play Game Services calls."]]