Need help with Android back key almost works.

I’m using storyboard. I want the Android back key to work just like touching the screen to go back. I started with the StoreBoard sample. Before adding the runtime key handler the app worked. With the runtime key handler in it works until I use the android back key - it goes back once but the second time hangs up.

In Scene2 in enterScene I add the runtime eventlistener, then in exitScene I remove it.

I appreciate any help in this.
thanks, leon …

Main.lua:

---------------------------------------------------------------------- main.lua  
--------------------------------------------------------------------  
display.setStatusBar( display.HiddenStatusBar )  
  
-- require controller module  
local storyboard = require "storyboard"  
local widget = require "widget"  
  
-- load first screen  
storyboard.gotoScene( "scene1" )  

Scene1.lua:

  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
  
local image, text1  
  
local function onSceneTouch( self, event )  
 if event.phase == "began" then  
 storyboard.gotoScene( "scene2", "fade", 200 )  
 return true  
 end  
end  
  
function scene:createScene( event )  
 local screenGroup = self.view  
  
 image = display.newImage( "bg.jpg" )  
 screenGroup:insert( image )  
  
 image.touch = onSceneTouch  
  
 text1 = display.newText( "Scene 1 touch for scene 2", 0, 0, native.systemFontBold, 24 )  
 text1:setTextColor( 255 )  
 text1:setReferencePoint( display.CenterReferencePoint )  
 text1.x, text1.y = display.contentWidth \* 0.5, 50  
 screenGroup:insert( text1 )  
  
end  
  
function scene:enterScene( event )  
 image:addEventListener( "touch", image )  
end  
  
function scene:exitScene( event )  
 image:removeEventListener( "touch", image )  
end  
  
function scene:destroyScene( event )  
end  
  
scene:addEventListener( "createScene", scene )  
scene:addEventListener( "enterScene", scene )  
scene:addEventListener( "exitScene", scene )  
scene:addEventListener( "destroyScene", scene )  
  
return scene  

Scene2.lua:

[code]

local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

local image, text1

local function onSceneTouch( self, event )
if event.phase == “began” then
storyboard.gotoScene( “scene1”, “fade”, 200 )
return true
end
end

local function handleBackButton( event)
if (event.phase == “down”) and (event.keyName ==“back”) then
storyboard.gotoScene( true, “scene1”, “fade”, 200 )
end
return true
end

function scene:createScene( event )
local screenGroup = self.view
image = display.newImage( “bg2.jpg” )
screenGroup:insert( image )

image.touch = onSceneTouch

text1 = display.newText( “Scene 2 touch to go back”, 0, 0, native.systemFontBold, 24 )
text1:setTextColor( 255 )
text1:setReferencePoint( display.CenterReferencePoint )
text1.x, text1.y = display.contentWidth * 0.5, 50
screenGroup:insert( text1 )
end

function scene:enterScene( event )
Runtime:addEventListener( “key”, handleBackButton )
image:addEventListener( “touch”, image )
end

function scene:exitScene()
image:removeEventListener( “touch”, image )
Runtime:removeEventListener ( “key”, handleBackbutton )
end

function scene:destroyScene( event )
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

return scene
[/code] [import]uid: 101604 topic_id: 25087 reply_id: 325087[/import]