Question

I have this problem for quite long now and still cannot find solution. This is how I call sample Google Play Games activity from java code:

    final int RC_ACHIEVEMENTS = 100;

    final GameActivity activity = ((GameActivity) mContext);

    final GoogleApiClient apiClient = activity.getApiClient();
    if (apiClient.isConnected()) {
        Intent intent = Games.Achievements.getAchievementsIntent(activity.getApiClient());
        activity.startActivityForResult(intent, RC_ACHIEVEMENTS);
    }

In fact this is called from cocos code so I can do even that:

    final int RC_ACHIEVEMENTS = 100;

    final GameActivity activity = ((GameActivity) mContext);

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final GoogleApiClient apiClient = activity.getApiClient();
            if (apiClient.isConnected()) {
                Intent intent = Games.Achievements.getAchievementsIntent(activity.getApiClient());
                activity.startActivityForResult(intent, RC_ACHIEVEMENTS);
            }
        }
    });

but this is no necessary I think.

Now when I go to this activity and press home button everything works well. I can return to that activity via recent activities or via launcher icon.

But when I have don't keep activities developer option set or when I simply kill process and after that want return to that activity I end with crash.

In my understanding in this situation activity should create with Intent which cause it to start. It is working well with common android activities. It only crashes with Google Play Games activities.

First I think that this is maybe because I start it for result with startActivityForResult(). But after I test it with common android activity it also works well.

Someone has some experience with something like this?

Was it helpful?

Solution

The problem was in Java_org_cocos2dxRenderer.cpp.

This is current nativeOnPause method:

JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause() {
    Application::getInstance()->applicationDidEnterBackground();
}

This should be changed to:

JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause() {
    if(Application::getInstance()){
        Application::getInstance()->applicationDidEnterBackground();
    }
}

I don't know why Google Play Services Games activity act like that but this fixed problem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top