Hi.
I’m trying to overide the back android button.
I use in almost all my scenes:
local function moveBack() native.setKeyboardFocus(nil) Runtime:removeEventListener("key", onKeyEvent) menuCreator.changeScene(2,number) end local platformName = system.getInfo( "platformName" ) local function onKeyEvent( event ) local returnValue = false if (event.phase=="up") and (event.keyName=="back") and (platformName == "Android") then timers[1]=timer.performWithDelay(100,moveBack,1) returnValue=true end return returnValue end Runtime:addEventListener( "key", onKeyEvent )
the only scene i don’t have this event is the first scene so it can return to android, all other scenes if the user pressed the back button they will go to my main menu (scene 2). scene 1 is login page.
i don’t use composer to pass scenes. i use my internal code (changeScene(futureScene,PresentSceneToDelete))
the problem is that:
Runtime:removeEventListener("key", onKeyEvent)
is not removing this listener because when i go to my login page with my login button:
local function backToStart() Runtime:removeEventListener("key", onKeyEvent) changeScene(1,number) end
in my login page the lister is still working, because if i press the back button…it will change to my menu and not to android like it supposed to do.
i even created a new listener in scene 1 with:
local platformName = system.getInfo( "platformName" ) local function onKeyEvent( event ) local returnValue=false if ( event.phase=="up")and (event.keyName == "back") and (platformName == "Android") then native.setKeyboardFocus(nil) --Runtime:removeEventListener("key", onKeyEvent) end return returnValue end Runtime:addEventListener( "key", onKeyEvent )
but this doesn’t help…the other event from my other scene fires.
I’m lost here. don’t know what i’m doing wrong. any help is appreciated.
Best regards,
Carlos.
