Hi all,
I’ve been working on this for two days now with no luck. I’ve tried everything I can think of. I want the back button on Android to go to the menu scene if the app is not on the menu scene. If the app is already on the menu scene, I want the back button to exit the app.
I have tried placing the code in the main.lua file but the back button did not respond to my taps. I tried putting the code in each scene and removing the event listener upon scene exit but the app will always exit. If I am in a scene that is not the menu, the back button will make the app go to the menu scene then immediately exit.
Here is the code I have been using.
local function onKeyEvent(event) local phase = event.phase local keyName = event.keyName print( event.phase, event.keyName ) if ( "back" == keyName and phase == "up" ) then if storyboard.currentScene == "scene\_home" then native.requestExit() return true else storyboard.gotoScene( "scene\_home" ) return true end return false end end Runtime:addEventListener( "key", onKeyEvent )
Can someone please explain to me why this always exits the app? I would greatly appreciate it.
Eric