Lua Corona SDK:仅当用户按“重新启动应用程序”;“家”;
使用corona SDK,每次用户点击Home按钮时,我都希望我的应用程序能够干净地重新启动。 如果他/她接到电话,按下下拉菜单等,我希望应用程序继续处于“当前状态” 有什么建议吗 谢谢, / 这一款适用于android。 我从中查看,所以在iPhone中无法做到这一点 但您可以尝试这样做:获取应用程序挂起的时间。并将其保存到Documents目录。然后,当应用程序恢复时,检查两个会话之间的时间。如果时间超过半小时,请重新启动所有程序。我是如何解决的Lua Corona SDK:仅当用户按“重新启动应用程序”;“家”;,lua,coronasdk,onpause,Lua,Coronasdk,Onpause,使用corona SDK,每次用户点击Home按钮时,我都希望我的应用程序能够干净地重新启动。 如果他/她接到电话,按下下拉菜单等,我希望应用程序继续处于“当前状态” 有什么建议吗 谢谢, / 这一款适用于android。 我从中查看,所以在iPhone中无法做到这一点 但您可以尝试这样做:获取应用程序挂起的时间。并将其保存到Documents目录。然后,当应用程序恢复时,检查两个会话之间的时间。如果时间超过半小时,请重新启动所有程序。我是如何解决的 suspendTime = 0 resume
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)
我想你指的是iPhone?包括android(带homebutton的)和iPhone。感谢找到增量后不要忘记suspendTime=0和resumeTime=0;)顺便问一下,os.time()是否总是返回小时?当您在23:59挂起应用程序并在00:01再次打开它时,它会做什么?我相信os:time是unix的时间戳。所以,我想它不会运行几分钟。不管怎样,你可以通过尝试或制造这个值来确保。如果一切正常,无需做任何事情。不,这不适用于android上的主页按钮,正如您在链接中看到的,它说:
主页
导航到主页”键(这不是android上的“主页”按钮)。
眼球回答很有魅力!
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)