Google Play Services C++ / 运行 UI 第二个 activity 使用 IntentHandler

Google Play Services C++ / Run UI on second activity using IntentHandler

我正在为 android 平台使用 Cocos2D-x 引擎开发手机游戏,我想在上面集成 GPGS。 我实现了显示排行榜,但有一个小烦人的问题。当排行榜可见时,如果我进入后台然后返回应用程序,游戏场景会变黑。我认为 opengl 上下文被释放并且不会再次恢复。在我看来 运行ning 排行榜在同一个 activity 上导致了这个,游戏引擎无法理解那里发生了什么。不管怎样,正因为如此,我想 运行 排行榜(以及所有 GPGS 的东西)在一个新的 activity 上使用 intent.

Google likes "Providing" In the reference documents of Google Play Game Services C++ SDK, there is a few unclear/fuzzy explanation about using SetOptionalIntentHandlerForUI method.

"Provide a function that can start a provided UI intent at any point, using startActivityForResult."

What is the mean of "Providing"? What is a provided Intent? How will I use startActivityForResult method? Unfortunately, "using" and "providing methods" are not clear expressions for coding. There is no sample about using this method in the documents of GPGS for C++. Eventually, Google's document is so poor and there is no useful information on the internet. If someone from Google helps me, I will be so happy.

据我了解,我是这样写代码的。但是启动的时候报错。

AppActivity.java

public void runGPGSActivity(Intent i) {
    startActivityForResult(i,100);
}

AndroidPlatformConfiguration.h(来自 C++ gpg 库)

typedef std::function<void(jobject)> IntentHandler;

AndroidPlatformConfiguration &SetOptionalIntentHandlerForUI(
IntentHandler intent_handler);

main.cpp(JNI 绑定、工作代码、GPGS 运行s 在同一个 activity 上)

gpg::AndroidPlatformConfiguration platform_configuration;
platform_configuration.SetActivity(activity);
StateManager::InitServices( ...

main.cpp(JNI 绑定,新 activity 上的 GPGS 必须是 运行)

gpg::AndroidPlatformConfiguration platform_configuration;

jclass activityClass = env->FindClass("org/cocos2dx/cpp/AppActivity");
jmethodID jIntentHandlerMethodID = env->GetMethodID(activityClass,"runGPGSActivity","(Landorid/content/Intent;)V");
jobject jIntentHandler = env->NewObject(activityClass, jIntentHandlerMethodID);

gpg::AndroidPlatformConfiguration::IntentHandler mIntentHandler; /*= [](jobject mjIntentHandler){};*/
std::function<void(jobject)> intentHandler = std::bind(mIntentHandler,jIntentHandler);

platform_configuration.SetOptionalIntentHandlerForUI(intentHandler);
platform_configuration.SetActivity(activity);

StateManager::InitServices(

没有构建错误,但应用程序在启动时崩溃。

03-24 14:12:24.301: A/libc(21352): Fatal signal 6 (SIGABRT) at 0x00005368 (code=-6), thread 21352 (main)

以及有关此问题的一些链接:

IntentHandler reference

StartActivityForResult reference

/// 在此先感谢您。 ///

...是的,我解决了问题,但没有使用 IntentHandler 方法。

我在我的应用中使用这段代码来显示每周排行榜数据。

gameServices->Leaderboards().ShowUIBlocking(leaderboardId,gpg::LeaderboardTimeSpan::WEEKLY);

但是 return 值不是空的,它是 UIStatus(不管它是什么)

我已经恢复到此代码,应用程序现在不会黑屏。此方法 return 无效,我认为在使用 ShowUIBlocking 方法和 UIStatus 时我必须捕获一些回调。

gameServices->Leaderboards().ShowUI(leaderboardId);

但是现在,我无法从排行榜的时间跨度功能中获益。

我打算研究一下它的使用方法。目前没有问题。但是,SetOptionalIntentHandlerForUI 的文档必须写得更明确,对于想要使用它的程序员。