I’ve added a runtime listener to use Android’s hardware back button in storyboard as follows:
[lua]
local onKeyEvent = function(event)
local keyname = event.keyName
if (event.phase == “up” and event.keyName==“back”) then
storyboard.gotoScene(“scripts.scene1”)
end
return true
end
function scene:enterScene(event)
if system.getInfo( “platformName” ) == “Android” then
Runtime:addEventListener( “key”, onKeyEvent )
end
end
function scene:exitScene(event)
end
function scene:destroyScene(event)
if system.getInfo( “platformName” ) == “Android” then
Runtime:removeEventListener(“key”, onKeyEvent)
end
end
[/lua]
However, upon the destroyScene event, the event listener is not being removed. Why is this? I’ve tried changing the code to
[lua]
local onKeyEvent = function(event)
local keyname = event.keyName
if (event.phase == “up” and event.keyName==“back”) then
storyboard.gotoScene(“scripts.scene1”)
end
return true
end
function scene:enterScene(event)
if system.getInfo( “platformName” ) == “Android” then
local Runtime:addEventListener( “key”, onKeyEvent )
end
end
function scene:exitScene(event)
end
function scene:destroyScene(event)
if system.getInfo( “platformName” ) == “Android” then
local Runtime:removeEventListener(“key”, onKeyEvent)
end
end
[/lua]
but this gives me errors when trying to build the app for android. Any suggestions?