如何赶上退出应用程序事件? [英] How to catch exit app event?

查看:74
本文介绍了如何赶上退出应用程序事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我需要在phonegap应用程序中捕获退出应用程序事件.实际上,如果播放器尝试以最小化作弊并退出应用程序并在他已经启动新的lvl时从任务管理器中退出,则我想触发looseLife()函数.如果他正确退出,请按后退"按钮.

Hy! I need to catch the exit app event in my phonegap application. Actually I want to trigger a looseLife() function if the player tries to cheat and exit the app with minimize and exit from task manager while he already started a new lvl. If he exit it correctly, by pressing the back button it works fine.

我尝试过onunload或onbeforeunload,但是只有在我正常关闭应用程序时才会调用这些函数,而不会最小化它并从任务管理器中将其关闭.

I tried onunload or onbeforeunload but these functions get called only if I close the app normally, without minimizing it and closing it from task manager.

暂停功能也无济于事,因为它在屏幕锁定或用户切换到另一个应用并再次返回时也会触发.

The pause function also doesn't help me because it gets triggered also if the screen is locked or when the user switches to another app and than back again.

如何在任务管理器中最小化和关闭应用程序时捕获事件?

How to catch the event when the app is minimized and closed in the task manager?

推荐答案

我发现window.onbeforeunload可以更好地清理资源.可能不在主题范围内,但我认为window.onbeforeunload不会造成任何竞争条件类型问题.

I found window.onbeforeunload to work better for cleaning up resources. Possibly off topic but I think window.onbeforeunload wouldn't create any race condition type issues.

这篇关于如何赶上退出应用程序事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆