Back button is not working in Simulator

I tried following this postand have been unable to get the Back button to work in either the simulator or on my phone. I used the code referred to on this blogand tried to print out on Key Event… but nothing happens. What can I be doing wrong?

I tried putting the onKeyEvent function in main.lua and other lua files, but nothing happens (I do add the event listeners)

Can you post your code?

 Here is the code… At launch, the main.lua file just fires up the database and goes to splash screen:

MAIN.LUA

display.setStatusBar(display.HiddenStatusBar) ------------------------ -- Managging Database -- ------------------------ require "sqlite3" local data\_path=system.pathForFile("data.db",system.DocumentsDirectory); db=sqlite3.open(data\_path); local sql= "CREATE TABLE IF NOT EXISTS settings (name,value);" db:exec(sql); function setSetting(name,value)        sql="DELETE FROM settings WHERE name='"..name.."'";     db:exec( sql )          sql="INSERT INTO settings (name,value) VALUES ('"..name.."',"..value..");";     db:exec( sql )     end function getSetting(name)     local sql="SELECT \* FROM settings WHERE name='"..name.."'";     local value=-1;     for row in db:nrows(sql) do         value=row.value;     end         return value; end local storyboard = require "storyboard" storyboard.gotoScene("splash", "fade")  

The Splash screen just shows the image and moves onto Menu.lua

splash.lua

local storyboard = require "storyboard" local scene = storyboard.newScene() local scaleX = display.contentWidth / 480 local scaleY = display.contentHeight/ 860 local background function scene:createScene(event)     local screenGroup = self.view          -- Background --     background = display.newImage ("splashscreen.png")     background.x = display.contentWidth/2     background.y = display.contentHeight/2     background.xScale = scaleX     background.yScale = scaleY     screenGroup:insert(background)         end function LoadMenu()     storyboard.gotoScene("menu", "fade", 500) end function scene:enterScene(event)     end function scene:exitScene(event)      end function scene:destroyScene(event) end timer.performWithDelay(2000, LoadMenu, 1) scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene   

Menu.lua

I have defined the function to handle the hardware button right at the end

local storyboard = require "storyboard" local gamestate = require( "gamestate" ) local scene = storyboard.newScene() local background, playButton, aboutButton, exitButton local scaleX = display.contentWidth / 480 local scaleY = display.contentHeight/ 860 function scene:createScene(event) &nbsp;&nbsp;&nbsp;&nbsp;local music = audio.loadStream("music.mp3") &nbsp;&nbsp;&nbsp;&nbsp;audio.play(music, { channel=1, loops=-1 }) &nbsp;&nbsp;&nbsp;&nbsp;local screenGroup = self.view &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;-- Background -- &nbsp;&nbsp;&nbsp;&nbsp;background = display.newImage ("menubackground.png") &nbsp;&nbsp;&nbsp;&nbsp;background.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;background.y = display.contentHeight/2 &nbsp;&nbsp;&nbsp;&nbsp;background.xScale = background.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;background.yScale = background.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(background) &nbsp;&nbsp;&nbsp;&nbsp;-- Play Button -- &nbsp;&nbsp;&nbsp;&nbsp;playButton = display.newImage ("menuImages/Play.png") &nbsp;&nbsp;&nbsp;&nbsp;playButton.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;playButton.y = display.contentHeight \* 1/8 &nbsp;&nbsp;&nbsp;&nbsp;playButton.xScale = playButton.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;playButton.yScale = playButton.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(playButton) &nbsp;&nbsp;&nbsp;&nbsp;-- About Button -- &nbsp;&nbsp;&nbsp;&nbsp;aboutButton = display.newImage ("menuImages/About.png") &nbsp;&nbsp;&nbsp;&nbsp;aboutButton.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;aboutButton.y = display.contentHeight \* 3/8 &nbsp;&nbsp;&nbsp;&nbsp;aboutButton.xScale = aboutButton.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;aboutButton.yScale = aboutButton.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(aboutButton) &nbsp;&nbsp;&nbsp;&nbsp;-- Tutorial Button -- &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton = display.newImage ("menuImages/Tutorial.png") &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton.y = display.contentHeight \* 5/8 &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton.xScale = tutorialButton.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton.yScale = tutorialButton.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(tutorialButton) &nbsp;&nbsp;&nbsp;&nbsp;-- Exit Button -- &nbsp;&nbsp;&nbsp;&nbsp;exitButton = display.newImage ("menuImages/Exit.png") &nbsp;&nbsp;&nbsp;&nbsp;exitButton.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;exitButton.y = display.contentHeight \* 7/8 &nbsp;&nbsp;&nbsp;&nbsp;exitButton.xScale = exitButton.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;exitButton.yScale = exitButton.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(exitButton) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;--\> ------------------------ \<-- end local function pressPlay (event) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;storyboard.gotoScene("stages", "fade", 500) &nbsp;&nbsp;&nbsp;&nbsp;end end local function pressAbout (event) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;storyboard.gotoScene("about", "fade", 500) &nbsp;&nbsp;&nbsp;&nbsp;end end local function pressTutorial (event) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;storyboard.gotoScene("howtoplay", "fade", 500) &nbsp;&nbsp;&nbsp;&nbsp;end end local function pressExit (event) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;os.exit() &nbsp;&nbsp;&nbsp;&nbsp;end end function scene:enterScene(event) &nbsp;&nbsp;&nbsp;&nbsp;local prior\_scene = storyboard.getPrevious() &nbsp;&nbsp;&nbsp;&nbsp;storyboard.purgeScene( prior\_scene ) &nbsp;&nbsp;&nbsp;&nbsp;storyboard.removeAll() &nbsp;&nbsp;&nbsp;&nbsp;-- if (gamestate.level \< 10) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- storyboard.purgeScene("level0" .. gamestate.level) &nbsp;&nbsp;&nbsp;&nbsp;-- end &nbsp;&nbsp;&nbsp;&nbsp;-- if (gamestate.level \>= 10) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- storyboard.purgeScene("level" .. gamestate.level) &nbsp;&nbsp;&nbsp;&nbsp;-- end &nbsp;&nbsp;&nbsp;&nbsp;playButton:addEventListener ("touch", pressPlay) &nbsp;&nbsp;&nbsp;&nbsp;aboutButton:addEventListener ("touch", pressAbout) &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton:addEventListener ("touch", pressTutorial) &nbsp;&nbsp;&nbsp;&nbsp;exitButton:addEventListener ("touch", pressExit) end function scene:exitScene(event) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;playButton:removeEventListener ("touch", pressPlay) &nbsp;&nbsp;&nbsp;&nbsp;aboutButton:removeEventListener ("touch", pressAbout) &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton:removeEventListener ("touch", pressTutorial) &nbsp;&nbsp;&nbsp;&nbsp;exitButton:removeEventListener ("touch", pressExit) &nbsp;&nbsp;&nbsp;&nbsp; end function scene:destroyScene(event) &nbsp;&nbsp;&nbsp;&nbsp;local screenGroup = self.view end &nbsp;&nbsp;&nbsp;&nbsp; local function onKeyEvent( event ) &nbsp;&nbsp;&nbsp;&nbsp;print("event happened") &nbsp;&nbsp;&nbsp;&nbsp;local phase = event.phase &nbsp;&nbsp;&nbsp;&nbsp;local keyName = event.keyName &nbsp;&nbsp;&nbsp;&nbsp;if ( "back" == keyName and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;native.requestExit() &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;if ( keyName == "volumeUp" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( masterVolume \< 1.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masterVolume = masterVolume + 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;elseif ( keyName == "volumeDown" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( masterVolume \> 0.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masterVolume = masterVolume - 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;return false &nbsp;--SEE NOTE BELOW end --add the key callback Runtime:addEventListener( "key", onKeyEvent ) &nbsp;&nbsp;&nbsp;&nbsp; scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene &nbsp;

Personally I would put the key handling in your main.lua before you call storyboard.gotoScene().    The code you have looks right.  The way you have it written, your app should exit when the back button is pressed.

Also, you should put your 2 second timer inside the the splash.lua’s enterScene() function.

Shifted the code to main.lua, but nothing is happening. Also corrected the splash screen timer thing as suggested. The new code is :

display.setStatusBar(display.HiddenStatusBar) local storyboard = require "storyboard" ------------------------ -- Managging Database -- ------------------------ require "sqlite3" local data\_path=system.pathForFile("data.db",system.DocumentsDirectory); db=sqlite3.open(data\_path); local sql= "CREATE TABLE IF NOT EXISTS settings (name,value);" db:exec(sql); function setSetting(name,value) &nbsp;&nbsp; &nbsp; &nbsp; sql="DELETE FROM settings WHERE name='"..name.."'"; &nbsp; &nbsp; db:exec( sql ) &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; sql="INSERT INTO settings (name,value) VALUES ('"..name.."',"..value..");"; &nbsp; &nbsp; db:exec( sql ) &nbsp; &nbsp; end function getSetting(name) &nbsp; &nbsp; local sql="SELECT \* FROM settings WHERE name='"..name.."'"; &nbsp; &nbsp; local value=-1; &nbsp; &nbsp; for row in db:nrows(sql) do &nbsp; &nbsp; &nbsp; &nbsp; value=row.value; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; return value; end &nbsp;&nbsp;&nbsp;&nbsp; local function onKeyEvent( event ) &nbsp;&nbsp;&nbsp;&nbsp;print("event happened") &nbsp;&nbsp;&nbsp;&nbsp;local phase = event.phase &nbsp;&nbsp;&nbsp;&nbsp;local keyName = event.keyName &nbsp;&nbsp;&nbsp;&nbsp;if ( "back" == keyName and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;native.requestExit() &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;if ( keyName == "volumeUp" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( masterVolume \< 1.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masterVolume = masterVolume + 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;elseif ( keyName == "volumeDown" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( masterVolume \> 0.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masterVolume = masterVolume - 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;return false &nbsp;--SEE NOTE BELOW end --add the key callback Runtime:addEventListener( "key", onKeyEvent ) storyboard.gotoScene("splash", "fade") &nbsp;

Since the key handling is now only taking place in this lua file I just posted its code

Are you trying this in the Corona simulator?  Backbuttons are a device only feature.  You would need to have it on your device to test it.

Rob

Can you post your code?

 Here is the code… At launch, the main.lua file just fires up the database and goes to splash screen:

MAIN.LUA

display.setStatusBar(display.HiddenStatusBar) ------------------------ -- Managging Database -- ------------------------ require "sqlite3" local data\_path=system.pathForFile("data.db",system.DocumentsDirectory); db=sqlite3.open(data\_path); local sql= "CREATE TABLE IF NOT EXISTS settings (name,value);" db:exec(sql); function setSetting(name,value) &nbsp;&nbsp; &nbsp; &nbsp; sql="DELETE FROM settings WHERE name='"..name.."'"; &nbsp; &nbsp; db:exec( sql ) &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; sql="INSERT INTO settings (name,value) VALUES ('"..name.."',"..value..");"; &nbsp; &nbsp; db:exec( sql ) &nbsp; &nbsp; end function getSetting(name) &nbsp; &nbsp; local sql="SELECT \* FROM settings WHERE name='"..name.."'"; &nbsp; &nbsp; local value=-1; &nbsp; &nbsp; for row in db:nrows(sql) do &nbsp; &nbsp; &nbsp; &nbsp; value=row.value; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; return value; end local storyboard = require "storyboard" storyboard.gotoScene("splash", "fade") &nbsp;

The Splash screen just shows the image and moves onto Menu.lua

splash.lua

local storyboard = require "storyboard" local scene = storyboard.newScene() local scaleX = display.contentWidth / 480 local scaleY = display.contentHeight/ 860 local background function scene:createScene(event) &nbsp;&nbsp;&nbsp;&nbsp;local screenGroup = self.view &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;-- Background -- &nbsp;&nbsp;&nbsp;&nbsp;background = display.newImage ("splashscreen.png") &nbsp;&nbsp;&nbsp;&nbsp;background.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;background.y = display.contentHeight/2 &nbsp;&nbsp;&nbsp;&nbsp;background.xScale = scaleX &nbsp;&nbsp;&nbsp;&nbsp;background.yScale = scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(background)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end function LoadMenu() &nbsp;&nbsp;&nbsp;&nbsp;storyboard.gotoScene("menu", "fade", 500) end function scene:enterScene(event)&nbsp;&nbsp;&nbsp;&nbsp; end function scene:exitScene(event) &nbsp;&nbsp;&nbsp;&nbsp; end function scene:destroyScene(event) end timer.performWithDelay(2000, LoadMenu, 1) scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene&nbsp; &nbsp;

Menu.lua

I have defined the function to handle the hardware button right at the end

local storyboard = require "storyboard" local gamestate = require( "gamestate" ) local scene = storyboard.newScene() local background, playButton, aboutButton, exitButton local scaleX = display.contentWidth / 480 local scaleY = display.contentHeight/ 860 function scene:createScene(event) &nbsp;&nbsp;&nbsp;&nbsp;local music = audio.loadStream("music.mp3") &nbsp;&nbsp;&nbsp;&nbsp;audio.play(music, { channel=1, loops=-1 }) &nbsp;&nbsp;&nbsp;&nbsp;local screenGroup = self.view &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;-- Background -- &nbsp;&nbsp;&nbsp;&nbsp;background = display.newImage ("menubackground.png") &nbsp;&nbsp;&nbsp;&nbsp;background.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;background.y = display.contentHeight/2 &nbsp;&nbsp;&nbsp;&nbsp;background.xScale = background.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;background.yScale = background.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(background) &nbsp;&nbsp;&nbsp;&nbsp;-- Play Button -- &nbsp;&nbsp;&nbsp;&nbsp;playButton = display.newImage ("menuImages/Play.png") &nbsp;&nbsp;&nbsp;&nbsp;playButton.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;playButton.y = display.contentHeight \* 1/8 &nbsp;&nbsp;&nbsp;&nbsp;playButton.xScale = playButton.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;playButton.yScale = playButton.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(playButton) &nbsp;&nbsp;&nbsp;&nbsp;-- About Button -- &nbsp;&nbsp;&nbsp;&nbsp;aboutButton = display.newImage ("menuImages/About.png") &nbsp;&nbsp;&nbsp;&nbsp;aboutButton.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;aboutButton.y = display.contentHeight \* 3/8 &nbsp;&nbsp;&nbsp;&nbsp;aboutButton.xScale = aboutButton.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;aboutButton.yScale = aboutButton.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(aboutButton) &nbsp;&nbsp;&nbsp;&nbsp;-- Tutorial Button -- &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton = display.newImage ("menuImages/Tutorial.png") &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton.y = display.contentHeight \* 5/8 &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton.xScale = tutorialButton.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton.yScale = tutorialButton.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(tutorialButton) &nbsp;&nbsp;&nbsp;&nbsp;-- Exit Button -- &nbsp;&nbsp;&nbsp;&nbsp;exitButton = display.newImage ("menuImages/Exit.png") &nbsp;&nbsp;&nbsp;&nbsp;exitButton.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;exitButton.y = display.contentHeight \* 7/8 &nbsp;&nbsp;&nbsp;&nbsp;exitButton.xScale = exitButton.xScale \* scaleX &nbsp;&nbsp;&nbsp;&nbsp;exitButton.yScale = exitButton.yScale \* scaleY &nbsp;&nbsp;&nbsp;&nbsp;screenGroup:insert(exitButton) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;--\> ------------------------ \<-- end local function pressPlay (event) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;storyboard.gotoScene("stages", "fade", 500) &nbsp;&nbsp;&nbsp;&nbsp;end end local function pressAbout (event) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;storyboard.gotoScene("about", "fade", 500) &nbsp;&nbsp;&nbsp;&nbsp;end end local function pressTutorial (event) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;storyboard.gotoScene("howtoplay", "fade", 500) &nbsp;&nbsp;&nbsp;&nbsp;end end local function pressExit (event) &nbsp;&nbsp;&nbsp;&nbsp;if event.phase == "began" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;os.exit() &nbsp;&nbsp;&nbsp;&nbsp;end end function scene:enterScene(event) &nbsp;&nbsp;&nbsp;&nbsp;local prior\_scene = storyboard.getPrevious() &nbsp;&nbsp;&nbsp;&nbsp;storyboard.purgeScene( prior\_scene ) &nbsp;&nbsp;&nbsp;&nbsp;storyboard.removeAll() &nbsp;&nbsp;&nbsp;&nbsp;-- if (gamestate.level \< 10) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- storyboard.purgeScene("level0" .. gamestate.level) &nbsp;&nbsp;&nbsp;&nbsp;-- end &nbsp;&nbsp;&nbsp;&nbsp;-- if (gamestate.level \>= 10) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- storyboard.purgeScene("level" .. gamestate.level) &nbsp;&nbsp;&nbsp;&nbsp;-- end &nbsp;&nbsp;&nbsp;&nbsp;playButton:addEventListener ("touch", pressPlay) &nbsp;&nbsp;&nbsp;&nbsp;aboutButton:addEventListener ("touch", pressAbout) &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton:addEventListener ("touch", pressTutorial) &nbsp;&nbsp;&nbsp;&nbsp;exitButton:addEventListener ("touch", pressExit) end function scene:exitScene(event) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;playButton:removeEventListener ("touch", pressPlay) &nbsp;&nbsp;&nbsp;&nbsp;aboutButton:removeEventListener ("touch", pressAbout) &nbsp;&nbsp;&nbsp;&nbsp;tutorialButton:removeEventListener ("touch", pressTutorial) &nbsp;&nbsp;&nbsp;&nbsp;exitButton:removeEventListener ("touch", pressExit) &nbsp;&nbsp;&nbsp;&nbsp; end function scene:destroyScene(event) &nbsp;&nbsp;&nbsp;&nbsp;local screenGroup = self.view end &nbsp;&nbsp;&nbsp;&nbsp; local function onKeyEvent( event ) &nbsp;&nbsp;&nbsp;&nbsp;print("event happened") &nbsp;&nbsp;&nbsp;&nbsp;local phase = event.phase &nbsp;&nbsp;&nbsp;&nbsp;local keyName = event.keyName &nbsp;&nbsp;&nbsp;&nbsp;if ( "back" == keyName and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;native.requestExit() &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;if ( keyName == "volumeUp" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( masterVolume \< 1.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masterVolume = masterVolume + 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;elseif ( keyName == "volumeDown" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( masterVolume \> 0.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masterVolume = masterVolume - 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;return false &nbsp;--SEE NOTE BELOW end --add the key callback Runtime:addEventListener( "key", onKeyEvent ) &nbsp;&nbsp;&nbsp;&nbsp; scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene &nbsp;

Personally I would put the key handling in your main.lua before you call storyboard.gotoScene().    The code you have looks right.  The way you have it written, your app should exit when the back button is pressed.

Also, you should put your 2 second timer inside the the splash.lua’s enterScene() function.

Shifted the code to main.lua, but nothing is happening. Also corrected the splash screen timer thing as suggested. The new code is :

display.setStatusBar(display.HiddenStatusBar) local storyboard = require "storyboard" ------------------------ -- Managging Database -- ------------------------ require "sqlite3" local data\_path=system.pathForFile("data.db",system.DocumentsDirectory); db=sqlite3.open(data\_path); local sql= "CREATE TABLE IF NOT EXISTS settings (name,value);" db:exec(sql); function setSetting(name,value) &nbsp;&nbsp; &nbsp; &nbsp; sql="DELETE FROM settings WHERE name='"..name.."'"; &nbsp; &nbsp; db:exec( sql ) &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; sql="INSERT INTO settings (name,value) VALUES ('"..name.."',"..value..");"; &nbsp; &nbsp; db:exec( sql ) &nbsp; &nbsp; end function getSetting(name) &nbsp; &nbsp; local sql="SELECT \* FROM settings WHERE name='"..name.."'"; &nbsp; &nbsp; local value=-1; &nbsp; &nbsp; for row in db:nrows(sql) do &nbsp; &nbsp; &nbsp; &nbsp; value=row.value; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; return value; end &nbsp;&nbsp;&nbsp;&nbsp; local function onKeyEvent( event ) &nbsp;&nbsp;&nbsp;&nbsp;print("event happened") &nbsp;&nbsp;&nbsp;&nbsp;local phase = event.phase &nbsp;&nbsp;&nbsp;&nbsp;local keyName = event.keyName &nbsp;&nbsp;&nbsp;&nbsp;if ( "back" == keyName and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;native.requestExit() &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;if ( keyName == "volumeUp" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( masterVolume \< 1.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masterVolume = masterVolume + 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;elseif ( keyName == "volumeDown" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( masterVolume \> 0.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masterVolume = masterVolume - 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;return false &nbsp;--SEE NOTE BELOW end --add the key callback Runtime:addEventListener( "key", onKeyEvent ) storyboard.gotoScene("splash", "fade") &nbsp;

Since the key handling is now only taking place in this lua file I just posted its code

Are you trying this in the Corona simulator?  Backbuttons are a device only feature.  You would need to have it on your device to test it.

Rob