I am trying to handle the back button and it seems like it is calling the same handler more than once and I can’t figure out why. Here is my code:
local function onBackButtonPressedChild(e) print("------------------Childburn-----------------") if (e.phase == "down" and (e.keyName == "back" or e.keyName == "escape")) then --Here the key was pressed downPress = true print("-----backbuttonpressed - back/esc down") return true else if (e.phase == "up" and (e.keyName == "back" or e.keyName == "escape") and downPress==true) then downPress = false print("-----backbuttonpress - up") GoBack() return true end end return false end Runtime:addEventListener( "key", onBackButtonPressedChild )
So, it looks like they press it (phase = down) ad I’m setting downPress to true. So then they release it (phase = up AND downPress = true) so it runs GoBack.
The only problem is… it appears that when I press ESC (I can’t use back button in the simulator), it calls the routine twice… the first time, I see that it sees the downpress, and then jumps back to the main menu… then tries to execute the GoBack routine and fails, because the go back hides/deletes elements on the scene which no longer exist.
The scene that calls the scene that contains this has its own handler for the back button, but it is removed when the goto.scene is called for this scene… it basically goes… main menu -> burn tools -> this scene
So why does it go back to the main menu and then try to execute the code a second time?
EDIT - So it looks like it’s calling the PREVIOUS scenes backbutton handling routine as well (at the same time)… even though, on launching this scene I use the following code to remove the listener right before the goto.scene
Runtime:removeEventListener( "key", onBackButtonPressedBurn) storyboard.gotoScene( "scene\_childburn" )