Storyboard android back button

You should have the function and the call to add the event listener in main.lua.  Can you post your whole listener function?

Yes i have done that thanks.

[lua]

local function androKeyEvent(event)

    local phase = event.phase

    local returnValue = false

   

    if(phase == “down”) then

        local keyName = event.keyName

        local currentScene = storyboard.getCurrentSceneName()

        local function toExit( event )

            if (“clicked”==event.action) and (event.index==1) then

                native.requestExit()

            end

        end

        local function toMenu( event )

            if (“clicked”==event.action) and (event.index==1) then

                storyboard.gotoScene( “menu”, { effect=“crossFade”, time=200 } )

            end

        end

       

        if ( “back” == keyName ) then

            returnValue = true

            if ( currentScene==“splash” ) then

                native.requestExit()

            elseif ( currentScene==“menu” ) then

                if ( storyboard.isOverlay ) then

                    storyboard.hideOverlay()

                else

                    local alert = native.showAlert( “”, “Sure to exit ?”, { “Yes”, “No” }, toExit )

                end        

            elseif ( currentScene==“game” ) then    

                if ( storyboard.isOverlay ) then

                    storyboard.hideOverlay()

                else

                  – still working on this part. lots of print() and other stuff, so i remove this

                  local alert = native.showAlert( “”, “Back to MENU ?”, { “Yes”, “No” }, toMenu )

                end

            end

        end

    end

   

    return returnValue   

end

if(device.isAndroid) then

    Runtime:addEventListener( “key”,androKeyEvent )

end

[/lua]

That’s my listener Rob, if you want to take a look.

It doesn’t close the app anymore. But still, something wrong?

If you handle the back button, you should return true, but for other buttons return false.

As for what’s going on, put in some print statements and look at your log.  Make sure you’re getting the scene name you’re expecting.  Make sure some other error condition isn’t happening.   I think it’s related to using your native.showAlert() call.  I’ve not seen apps ask that before.  Usually if I hit the back button I don’t want to be prompted.