how can I reset my app when exited?

I want the app to completely reset when the user receives a call or presses the home button or clicks an ad or anything else, so when they user opens the app again it starts over.

local onSystem = function( event )

    if event.type == “applicationStart” then

        print(“start”)

    elseif event.type == “applicationExit” then

        print(“exit”)

    elseif event.type == “applicationSuspend” then

        print(“suspend”)

    elseif event.type == “applicationResume” then

        print(“resume”)

    end

end

 

– setup a system event listener

Runtime:addEventListener( “system”, onSystem )

 

 

 

I have found this but I do not know what to put inside of the applicationSuspend block. Thanks!

You can put 

os.exit()

into your applicationSuspend block and this will force an exit to the OS. However, do read up on the caution (gotchas) on API page : 

http://docs.coronalabs.com/api/library/os/exit.html

oh ok ill be careful

It’s isn’t a matter of being careful.  Apple will reject your app if it just exits.  For Android you should use native.requestExit() instead.

Rob

I found another solution to my problem that did not involve os.exit() Thanks for the heads up though!

You can put 

os.exit()

into your applicationSuspend block and this will force an exit to the OS. However, do read up on the caution (gotchas) on API page : 

http://docs.coronalabs.com/api/library/os/exit.html

oh ok ill be careful

It’s isn’t a matter of being careful.  Apple will reject your app if it just exits.  For Android you should use native.requestExit() instead.

Rob

I found another solution to my problem that did not involve os.exit() Thanks for the heads up though!