Adding a quit button

I’m new to coding for corona lua so please bare with me if this is a stupid question.

im trying to create some type of quit button to quit my android app, here is the sample code but it’s not working. Im sure its a stupid mistake but here it is

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

local ui = require “scripts.lib.ui”
local radlib = require “scripts.lib.radlib”


– BEGINNING OF YOUR IMPLEMENTATION

local myButton = display.newImage( “quit.png” )

function myButton:tap( event )

     quit() os.exit() end timer.performWithDelay(1000,quit)    <-----THE IMPLEMENTATION IS WHERE THE PROBLEM IS.

myButton:addEventListener( “tap”, myButton )


– END OF YOUR IMPLEMENTATION


– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )

return scene

 

thank you for all the help.

try this

local function closeapp() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if&nbsp; system.getInfo("platformName")=="Android" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; native.requestExit() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; os.exit() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end end function myButton:tap( event ) &nbsp;&nbsp; &nbsp; timer.performWithDelay(1000,closeapp) end&nbsp;&nbsp;&nbsp; myButton:addEventListener( "tap", myButton ) &nbsp;

Finally! Thank you for your feedback!

You might find that you have to hide the button entirely on iOS. I’m not 100% sure, but I think their rules state that you cannot have an exit button, if the user wants to exit they have to use the home button.

On a similar note, why not just use the device’s back button to exit on Android? That will save you using up space with an exit button.

try this

local function closeapp() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if&nbsp; system.getInfo("platformName")=="Android" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; native.requestExit() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; os.exit() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end end function myButton:tap( event ) &nbsp;&nbsp; &nbsp; timer.performWithDelay(1000,closeapp) end&nbsp;&nbsp;&nbsp; myButton:addEventListener( "tap", myButton ) &nbsp;

Finally! Thank you for your feedback!

You might find that you have to hide the button entirely on iOS. I’m not 100% sure, but I think their rules state that you cannot have an exit button, if the user wants to exit they have to use the home button.

On a similar note, why not just use the device’s back button to exit on Android? That will save you using up space with an exit button.