Terminate Android App on Back Button Click

Hi everyone,

i have completely ported a game for ANDROID using cocos2dx and C++.
now i am having a problem with the termination of the game when the user clicks the back button.

i know how to handle back click event from CCLayer.
Can anyone suggest me how to terminate the game from CCScene.

i tried using keyBackClicked(), but it only works for CCLayer and not for CCScene.

can anyone tell me how to do that for CCScene.

The “back” soft key should be linked to CCDirector->popScene(). When the last scene is popped, the director terminates and your app should fall out to termination.

You can exit the game with following command:

@ CCDirector::sharedDirector()->end();@

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif

But how to apply it? I do not understand much, I’m sorry.

Can you help me how to do when clicking on the close button the game?

onLoad: function () {
    this.node.on ('mousedown', function (event) {
       "what's the code?"
    });

I was able to solve the problem by putting the following line of code.

this.node.on (‘touchstart’, function (event) {
cc.myScene.end ();
},

If you have other Scenes put the others too, and so on.

this.node.on (‘touchstart’, function (event) {
cc.myScene.end ();
cc.myOtherScene.end ();

},