Search code examples
luacoronasdkonpause

Corona SDK: Restart an app only when user press "home"


Using corona SDK, i would like a clean restart of my app, everytime the user hits the homebutton. If he/she receives a phonecall, pulls down the dropdownmenu and so on, I would like for the app to continue in its' current state.

Any suggestions?

Thanks, /S


Solution

  • how i solved it!

    suspendTime = 0
    resumeTime = 0
    
    function onSystemEvent( event )
        if event.type == "applicationSuspend" then
            suspendTime = os.time()
            print(suspendTime)
        elseif event.type == "applicationResume" then
            resumeTime = os.time()
            print(resumeTime)
            print("deltaTime: "..resumeTime - suspendTime )
                if(resumeTime - suspendTime > 30) then
                local sceneName = storyboard.getCurrentSceneName()
                if(sceneName ~= "levels.splash") then
                    print(sceneName)
                    print(resumeTime)
                            storyboard.gotoScene("levels.splash")
                end
            end
        end
    
    end
    Runtime:addEventListener("system", onSystemEvent)