How to Normally end up a game on Android

Hello friends,

Who know how to normally end up a cocos2d-x based Android game? I’m very eager to get your help.

In detail, my case is:

In the main game scene (and the only scene in the scene stack), when the player clicks the BACK key,

a modal dialog will pop up letting him select whether to save data or not, in either case the game will

end up. For example, the two selections related buttons can be named “Save and Exit” and “Not save and Exit”.

In the above case, I found that I cannot simply invoke the following code:

CCDirector::sharedDirector()>end;
Which will result in some crash .
To dig further into the WHY, I simplified the above case to the following in the android case:
void GameLayer::keyBackClicked
{
CCDirector::sharedDirector
>end;
}
And also, I used the following code to release my game data:

void GameLayer::onExit
{
CCLayerColor::onExit;
CCLOG ("**************GameLayer::onExit()*");
UndoDeque.clear;//no needing to ensure the deque is not empty
AuxUndoDeque.clear;
Card
child;
CCObject* pObject = NULL;
//
for {
CCARRAY_FOREACH
{
child = pObject;
if{
this~~>removeChild;
}
}
}
for {
if!=0){
TableauPiles[i]>removeAllObjects();
TableauPiles[i]
>release;
}
}
for {
CCARRAY_FOREACH
{
child = pObject;
if{
this~~>removeChild(child,true);
}
}
}
for (int i = 0; i < 4; i++) {
if(FoundationPiles[i]>count!=0){
FoundationPiles[i]
>removeAllObjects();
FoundationPiles[i]>release;
}
}
for {
if {
this
>removeChild(Cells[i],true);
delete Cells[i];
Cells[i] = NULL;
} else
Cells[i] = NULL;
}

SimpleAudioEngine::sharedEngine()->end();
CCDirector::sharedDirector()->purgeCachedData();
}

But I still failed!

Well, my concluded puzzle is: how to normally end up a game (android) based on cocos2d-x, as well as release all game related data (some of which may be associated with sprites on the current screen)? I’ve been bewildered by this for a very long time? Could any friends all over the world lend my any help?