Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch exit app event?

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.

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?

like image 691
Alex Stanese Avatar asked May 01 '14 14:05

Alex Stanese


1 Answers

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.

like image 193
Michael Ribbons Avatar answered Sep 16 '22 19:09

Michael Ribbons