so i’m trying to figure out how to implement a “function” into physical back button on Android. then I found an explanation about “OnKeyEvent”. I tried to implement the standard GoToScene feature in storyboard for the “back” button, this is my code:
local function onKeyEvent( event ) -- Print which key was pressed down/up to the log. local message = "Key '" .. event.keyName .. "' was pressed " .. event.phase print( message ) if (event.keyName == "back" and event.phase == "up") then storyboard.gotoScene("scene3", {time=250, effect="crossFade", params = options}) print (" ok success") return true end return false end -- Add the key event listener. Runtime:addEventListener( "key", onKeyEvent );
when I test this in my android phone, it doesnt work properly. I mean, if I hit “back” button in that scene, yeah it changed scene but then it instantly changed scene again from the next one (where I also implement the onKeyEvent codes there). Basically it works like this within just one single touch on the “back” button: scene1 -> scene3 -> blank screen
when I check the log in eclipse logcat, apparently the key was like “pressed” twice because I saw the same print message twice as if I hit the back key several times. May I know what I did wrong?