when back button is pressed on android, the command of HomeScene is taken before pushed GameScene.

lets get into details.
i have got 3 scenes of interest

1)SplashScene-
replaced by(because i am not going to go back to that screen again)
2)HomeScene-
pushed in by(because i have to go back to that screen again if user presses back button)
(if i replace scene i get an error of “stackoverflow”, dint tried to get into it’s details)
3)Gamescene-
popped out (when back button is pressed)

the code being used-

s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, homeCall, this);
int32 homeCall(void* pSystemData, void* pUserData)
{
    s3eKeyboardEvent* pEvent = (s3eKeyboardEvent*) pSystemData;
    if (((pEvent->m_Key == s3eKeyAbsBSK) || (pEvent->m_Key == s3eKeyBackspace)) && pEvent->m_Pressed==0)
    {
        CCDirector::sharedDirector()->popScene();                 // on gamescene
                //exit(0);                                                // on homescene
    }
    return 0;
}

now my problem is that when i press the back button on gamescene,
the command******* exit;******* is executed first as that screen is still alive in background.

so, how to overcome this prob? any idea ?

Hi, you have commented the exit(0) funtion, where does it be invoked?
BTW, CCDirector::sharedDirector()>popScene function just removes current scene and pops the scene stack, it’s an asynchronous function. setNextScene will be invoked in the next frame.
<pre>
void CCDirector::popScene
{
CCAssert;
m_pobScenesStack
>removeLastObject();
unsigned int c = m_pobScenesStack~~>count;
if
{
end;
}
else
{
m_bSendCleanupToScene = true;
m_pNextScene = m_pobScenesStack~~>getObjectAtIndex(c - 1);
}
}

yes, running scene is not null. as gamescene is pushed on to homescene.

my gamescene code is:

s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, homeCall, this);
int32 homeCall(void* pSystemData, void* pUserData) {
s3eKeyboardEvent* pEvent = (s3eKeyboardEvent*) pSystemData;
if (((pEvent->m_Key s3eKeyAbsBSK) || (pEvent->m_Key s3eKeyBackspace)) && pEvent->m_Pressed==0) {
CCDirector::sharedDirector()->popScene(); 
}
return 0;
}

and my homescene code is:

s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, homeCall, this);
int32 homeCall(void* pSystemData, void* pUserData) {
s3eKeyboardEvent* pEvent = (s3eKeyboardEvent*) pSystemData;
if (((pEvent->m_Key s3eKeyAbsBSK) || (pEvent->m_Key s3eKeyBackspace)) && pEvent->m_Pressed==0) {
exit(0);
}
return 0;
}

but even on gamescene. exit 0; gets executed first. and so the game directly exits.

Hi, I know why this happens. s3eKeyboardRegister function just add your callback function pointer to the array, when key event appears, system iterate all elements of the array, homeCall in homeScene will be invoked first because of being added first. I don’t think you implement is a good way. For one application just invoke s3eKeyboardRegister once is enough.
You can refer to the construction of class CCEGLView in ‘CCEGLView_marmalade.cpp’:

CCEGLView::CCEGLView()
: m_pDelegate(NULL)
, m_fScreenScaleFactor(1.0)
, m_bNotHVGA(false)
, m_bCaptured(false)
, m_bAccelState(false)
, m_Key(s3eKeyFirst)
{
    IW_CALLSTACK("CCEGLView::CCEGLView");


    IwGLInit();

    m_sSizeInPixel.width = IwGLGetInt(IW_GL_WIDTH);
    m_sSizeInPixel.height = IwGLGetInt(IW_GL_HEIGHT);

    m_pSet      = new CCSet;
    m_pTouch    = new CCTouch;

    // Determine if the device supports multi-touch
    m_isMultiTouch = s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE) ? true : false;

    // For multi-touch devices we handle touch and motion events using different callbacks
    if (m_isMultiTouch)
    {
        s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, &MultiTouchEventHandler, this);
        s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, &MultiMotionEventHandler, this);

        for (int i = 0; i < S3E_POINTER_TOUCH_MAX; i++) {
            touchSet[i] = NULL;
        }
    }
    else
    {        
        // Register pointer touch button event handler
        s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, &TouchEventHandler, this);

        // Register pointer motion button event handler
        s3ePointerRegister(S3E_POINTER_MOTION_EVENT, &MotionEventHandler, this);
    }

    // Register keyboard event handler
//  s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, &KeyEventHandler, this);   // hack the code here, it should be called to listen the key event, i don't know why the author of marmalade port comment this line.
//  s3eKeyboardRegister(S3E_KEYBOARD_CHAR_EVENT, &CharEventHandler, this);
}

void CCEGLView::setKeyTouch(void* systemData)
{
// open the comment below. and judge the key value to fix your goal
//  s3eKeyboardEvent* event = (s3eKeyboardEvent*)systemData;
//  if (event->m_Pressed)
//  {
//      if (event->m_Key!=m_Key)
//      {
//          CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked);
//      }
//      else
//      {
//          CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
// 
//      }
//      m_Key =event->m_Key;
//  }
}

// Implement the keyMenuClicked function in your layer.
void KeypadTest::keyMenuClicked()
{
   // Balabala....
}

Hope this method will help you.

thank u james, its working now

int32 homeCall(void* pSystemData, void* pUserData)
{
    s3eKeyboardEvent* pEvent = (s3eKeyboardEvent*) pSystemData;
    if (((pEvent->m_Key == s3eKeyAbsBSK) || (pEvent->m_Key == s3eKeyBackspace)) && pEvent->m_Pressed==0)
    {
        CCDirector::sharedDirector()->popScene();                 

    }
    else if (((pEvent->m_Key == s3eKeyMenu) || (pEvent->m_Key == s3eKeySpace)) && pEvent->m_Pressed==0)
    {

        exit(0);                                               
    }
    return 0;
}