Thanks for the sample code! I tried it out, but unfortunately could not get it to work. However, after doing more research, I discovered this thread here:
http://developer.anscamobile.com/forum/2011/07/13/build-569
Supposedly, you cannot call a scene within the back key listener. Here is the final code that I used to get it to work on my HTC Desire S. It will send a user back to Screen 1 (screen1.lua) after the user presses the Back button on their Android device. I’m posting the final working code below to help others if they have the same problem as I did.
[code]
module(…, package.seeall)
– GROUPS
local localGroup = display.newGroup()
– BACK BUTTON FLAG
local backButtonPushed = false
– LISTENERS
local function animate(event)
if backButtonPushed == true then
backButtonPushed = false
director:changeScene(“screen1”)
– or
– os.exit()
end
end
local function onKeyEvent( event )
local phase = event.phase
local keyName = event.keyName
if phase == “up” and (keyName == “back”) then
backButtonPushed = true
end
return true
end
– INIT VARS
local function initVars ()
– Listeners
Runtime:addEventListener( “key”, onKeyEvent )
Runtime:addEventListener( “enterFrame”, animate )
end
– CLEAN
function clean ( event )
Runtime:removeEventListener( “key”, onKeyEvent )
Runtime:removeEventListener( “enterFrame”, animate )
backButtonPushed = nil
end
– NEW
function new()
– Initiate variables
initVars()
– MUST return a display.newGroup()
return localGroup
end
[/code] [import]uid: 82194 topic_id: 13985 reply_id: 51658[/import]