Both AppDelegate::applicationDidEnterBackground and applicationWillEnterForeground never get called on Android, so it’s not possible to (for example) pause the game and show a temporary screen when someone calls the user on his device.
The current code in org.cocos2dx.lib does not call these methods @ Activity.onPause and Activity.onResume. The C2DX/Java library code also seems to be somewhat out of sync between the HelloWorld and Tests samples. They’re both different.
I tried to fix it with this (new) code @ cocos2dx/platform/android/CocosdJni.cpp:
void Java_org_cocos2dx_lib_Cocos2dxActivity_nativeOnResume(JNIEnv* env)
{
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView()) return;
cocos2d::CCApplication::sharedApplication().applicationWillEnterForeground();
}
void Java_org_cocos2dx_lib_Cocos2dxActivity_nativeOnPause(JNIEnv* env)
{
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView()) return;
cocos2d::CCApplication::sharedApplication().applicationDidEnterBackground();
}
…where a call to nativeOnResume was added to org.cocos2dx.lib.Cocos2dxActivity.onResume and the same for the nativeOnPause method @ Activity.onPause .
The check for an OGL view was added because the shared application instance doesn’t exist yet when Activity.onResume is first called. But sadly, that won’t work either because libEGL will still complain with the following message: “call to OpenGL ES API with no current context (logged once per thread)”.
Does anyone else have an idea on how to fix this? It’s a very important feature to play nice with phone calls and all that…