Hi,
I read this tutorial (thanks Rob)
http://coronalabs.com/blog/2013/03/26/androidizing-your-mobile-app/
I currently work on “Android-izing” my iOS App
-
I used onKeyEvent listener
-
I add the key callback Runtime:addEventListener( “key”, onKeyEvent )
-
I add a member variable to the storyboard table called returnTo
-
I set this .returnTo property in each scene’s enterScene() event function.
Unfortunately, When I press the back button (on a Nexus 7 or on a Galaxy Note) It doesn’t work.
wherever I am, app exits.
Any help would be great.
Here is my code in main.lua :
local function onKeyEvent( event ) local phase = event.phase local keyName = event.keyName if keyName == "back" and phase == "up" then if storyboard.currentScene == "scripts.menuScene" then native.requestExit() else local lastScene = storyboard.returnTo if ( lastScene ) then storyboard.gotoScene( lastScene, "fade", 250 ) else --native.requestExit() end end end if ( keyName == "volumeUp" and phase == "down" ) then local masterVolume = audio.getVolume() if ( masterVolume \< 1.0 ) then masterVolume = masterVolume + 0.1 audio.setVolume( masterVolume ) end return true elseif ( keyName == "volumeDown" and phase == "down" ) then local masterVolume = audio.getVolume() if ( masterVolume \> 0.0 ) then masterVolume = masterVolume - 0.1 audio.setVolume( masterVolume ) end return true end return false end --add the key callback Runtime:addEventListener( "key", onKeyEvent )
Thanks
Olivier