THis is starting to drive me a little nuts. I’m trying to implement some simple actions for the Android back button, and running into some problems.
First, i’ve already looked at the blog post here: http://www.coronalabs.com/blog/2013/03/26/androidizing-your-mobile-app/
And have searched up and down the forums for answers. My code is very simple:
local function onKeyEvent( event ) local phase = event.phase local keyName = event.keyName print( event.phase, event.keyName ) if ( "back" == keyName and phase == "up" ) then storyboard.gotoScene( "menu", { effect="slideRight", time=800}) end return true end function scene:exitScene( event ) local group = self.view Runtime:removeEventListener( "key", onKeyEvent ) end
The problem i’m having is that halfway through the transition back to “menu” it crashes/closes.
After doing some playing around, i’ve figured out that the Back button is firing off twice? I figured this out by putting the same function in the “menu” scene but telling it to do nothing if the back button is pushed. By doing this, it then works like I want. But that doesn’t solve the problem, as I also need to put this code on a overlay, and the same thing is happening (The overlay closes, but the back button fires a second time transitioning back to the menu).
I’ve tried adding a event.phase == “ended” wrapper
I’ve tried adding 2 if statements, one for the “up” phase that does the transition and one for the “down” phase which does nothing.
Nothing seems to work, and the blog doesn’t help.
Forgot to mention I’m adding the Runtime listener for the key to every createScene function, and as you can see above removing it on exit.