Hi everyone, I’m facing with the following problem.
I bind the back key in android, when the user press
that key, the app launch a new activity (popup).
the popup has a title (“closing app”) and 2 buttons (yes/no).
if the user press “no”, the activity returns control to cocos2d-x, perfect.
but if the user press “yes”, the app try to close, but after it’s reopening.
some of my code:
btnExit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
popup.finish();
ExitPopupActivity.exitGame();
Cocos2dxHelper.terminateProcess();
}
});
public static native void exitGame();
extern "C" {
JNIEXPORT void JNICALL Java_bla_blabla_blablabla_ExitPopupActivity_exitGame(JNIEnv *, jclass)
{
CCDirector::sharedDirector()->end();
}
}
void Layer::keyBackClicked() {
#if (CC_TARGET_PLATFORM_2 == CC_PLATFORM_ANDROID)
JniMethodInfo minfo;
bool isHave = JniHelper::getStaticMethodInfo(minfo,"bla/blabla/blablabla/blablablabla", "getMainActivity", "()Ljava/lang/Object;");
jobject jobj = minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID);
isHave = JniHelper::getMethodInfo(minfo, "bla/blabla/blablabla/blablablabla", "showExitPopup", "()V");
if (isHave) {
minfo.env->CallVoidMethod(jobj, minfo.methodID);
}
#endif
}