透過集合功能整理內容
你可以依據偏好儲存及分類內容。
gpg::AndroidInitialization
#include <android_initialization.h>
AndroidInitialization 包含三個初始化函式,也就是必須呼叫其中一個函式。
摘要
如果是標準 Java 活動,則應使用 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 時,應在活動的 ANativeActivity_onCreate 執行期間呼叫 ANativeActivity_onCreate,然後才呼叫任何其他 Play 遊戲服務呼叫。
|
JNI_OnLoad(JavaVM *jvm)
|
void
將 Play 遊戲服務與標準 Java 活動搭配使用時,應在呼叫動態程式庫的 JNI_OnLoad 時呼叫 JNI_OnLoad。
|
android_main(struct android_app *app)
|
void
將 Play 遊戲服務與以 android_native_app_glue.h 為基礎的 NativeActivity 搭配使用時,應在活動的 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 時,應在活動的 ANativeActivity_onCreate 執行期間呼叫 ANativeActivity_onCreate,然後才呼叫任何其他 Play 遊戲服務呼叫。
JNI_OnLoad
void gpg::AndroidInitialization::JNI_OnLoad(
JavaVM *jvm
)
將 Play 遊戲服務與標準 Java 活動搭配使用時,應在呼叫動態程式庫的 JNI_OnLoad 時呼叫 JNI_OnLoad。
android_main
void gpg::AndroidInitialization::android_main(
struct android_app *app
)
將 Play 遊戲服務與以 android_native_app_glue.h 為基礎的 NativeActivity 搭配使用時,應在活動的 android_main 期間呼叫 android_main,然後再呼叫任何其他 Play 遊戲服務呼叫。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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."]]