Why does it call a key handler mulitple times?

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" )

Ok… so I contained the removeListener for the BACK button in a subroutine and am calling it with a print statement so I can see it fire… here are the results…

Scene1 - select button to goto scene 2, kill listener fires

Scene2 - hit back button… kill listener 2 fires… then goes to scene 1 and scene 1 listener fires…

Why is it doing this?  Is it because the back button routine goes to another scene without passing return true to the handler?  So Corona doesn’t recognize that the back button was in fact handled?

Ok… so I contained the removeListener for the BACK button in a subroutine and am calling it with a print statement so I can see it fire… here are the results…

Scene1 - select button to goto scene 2, kill listener fires

Scene2 - hit back button… kill listener 2 fires… then goes to scene 1 and scene 1 listener fires…

Why is it doing this?  Is it because the back button routine goes to another scene without passing return true to the handler?  So Corona doesn’t recognize that the back button was in fact handled?