3

We have an app as part of the Amazon Appstore webapp program, which allows web-apps to natively appear in their Appstore on e.g. Kindle Fire HDX. Our problem: The app doesn't exit and clear when closed, it's eternally stored in some persistent cache, causing issues with our concept of user sessions, websockets, remote user syncing and so on (it's a massively-multiplayer virtual world). How can we force the app to properly clear itself when being closed by the user?

(In XCode settings, a comparable boolean would be "UIApplicationExitsOnSuspend"...)

UpTheCreek
  • 31,444
  • 34
  • 152
  • 221
Philipp Lenssen
  • 8,818
  • 13
  • 56
  • 77
  • Does the Page Visibily API help? https://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active – Offbeatmammal Feb 09 '14 at 00:15
  • Did it help? kinda curious to see if it solved the problem – Offbeatmammal Feb 14 '14 at 06:18
  • Yes, we did a test using this code and it did solve it: we were able to launch an alert showing the time of closing (an alert that is seen when reopening). Thanks! – Philipp Lenssen Feb 14 '14 at 10:41
  • dang, I should have gone for the bounty answer! but serious... glad it helped – Offbeatmammal Feb 14 '14 at 14:53
  • Sigh, now I'm trying the same sample page again, and it doesn't work anymore. I'm closing Silk on my Kindle but the event is never caught. Strange. – Philipp Lenssen Feb 14 '14 at 17:33
  • Now got something working! if (isKindle) { window.onblur = window.onpagehide = function(e) { /* doStuff(); */ }; } // subject to Webapp test, but works in Silk – Philipp Lenssen Feb 14 '14 at 17:59
  • @Offbeatmammal - Re bounty: Please add your comment as an answer, it looks like the only one we will get ;) – UpTheCreek Feb 14 '14 at 18:53

1 Answers1

2

my initial suggestion was to use the PageVisibility API http://www.w3.org/TR/page-visibility/ (as suggested here Is there a way to detect if a browser window is not currently active?) but it looks like it also requires some more robust checking taking advantage of window.onblur as well per your own comment above

if (isKindle) { window.onblur = window.onpagehide = function(e) { /* doStuff(); */ }; } 
Offbeatmammal
  • 7,970
  • 2
  • 33
  • 52