コロナ SDK を使用して、ユーザーがホームボタンを押すたびに、アプリを完全に再起動したいと考えています。彼/彼女が電話を受けたり、ドロップダウンメニューをプルダウンしたりした場合、アプリを現在の状態で続行したいと思います。
助言がありますか?
ありがとう、/S
どのように私はそれを解決しました!
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)
function onKeyEvent( event )
local keyname = event.keyName;
if (event.phase == "up" and (event.keyName=="back" or event.keyName=="menu" or event.keyName == "home" )) then
if keyname == "menu" then
os.exit()
end
end
return false
end
Runtime:addEventListener( "key", onKeyEvent )
This one will work for android. I checked from http://docs.coronalabs.com/api/event/key/keyName.html, so there is no way to do that in iPhone.
But you can try this : get the time when application is suspended. And save it to documentes directory. Then when application is resume, check the time between two sessions. If there is more then half an hour, restart all things.