在Android 层提示的报错是:
03-14 09:54:21.080: E/cocos2d-x assert(19613): D:\Quick-Cocos2dx-Community/cocos/platform/android/CCApplication-android.cpp function:Application line:55
找到相应的代码
// sharedApplication pointer
Application * Application::sm_pSharedApplication = 0;
Application::Application()
{
CCAssert(! sm_pSharedApplication, “”);
sm_pSharedApplication = this;
}
原因是出现了断言错误,在网上百度了下都说在调用
Application::getInstance()->applicationDidEnterBackground();
的时候得加上Director::getInstance()->getOpenGLView()
查了下源代码在Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp
中有这样的代码
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause() {
if (Director::getInstance()->getOpenGLView()) {
Application::getInstance()->applicationDidEnterBackground();
cocos2d::EventCustom backgroundEvent(EVENT_COME_TO_BACKGROUND);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&backgroundEvent);
}
}
那为什么应用还是会被停止运行啊?