【发布时间】:2013-04-04 17:01:28
【问题描述】:
使用 corona SDK,我希望每次用户点击主页按钮时都重新启动我的应用程序。 如果他/她接到电话,拉下下拉菜单等,我希望应用程序继续保持其当前状态。
有什么建议吗?
谢谢, /S
【问题讨论】:
-
我猜你的意思是 iPhone ?
-
android(带有主页按钮的..)和 iPhone。谢谢
使用 corona 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 )
这个适用于安卓系统。 我检查了http://docs.coronalabs.com/api/event/key/keyName.html,所以在 iPhone 中没有办法做到这一点。
但是你可以试试这个:获取应用程序暂停的时间。并将其保存到文档目录。然后当应用程序恢复时,检查两个会话之间的时间。如果超过半小时,重新启动所有的东西。
【讨论】:
homePageThe "navigate to home page" key (this is not the "Home" button on Android). 眼球答案就像魅力一样!