How to properly close a Firefox OS app?

359 views Asked by At

I am developping an app to calculate the drift of a boat from its initial route. In the header I have a cancel (cross) button that should do 2 things when tapped:

  1. stop watching the position (the app uses the geolocation API)
  2. close the app and return to the home screen

I can do 1. with clearwatch, no problem:

document.getElementById("close").addEventListener("click", function( event ) {
  navigator.geolocation.clearWatch(geo);
});

But I don't know how to do 2. Any hint?

(I have noticed that very few apps proposed this "close" option and they stay open unless you force them to close through the Application Manager. Could this have an impact (pure speculation from me) on memory and performance?)

2

There are 2 answers

4
freddyb On BEST ANSWER

You can use window.close() to close windows. (This also works for other referenced window objects, e.g., pop-ups or window.opener.)

0
Aleh Zasypkin On

In addition to what @freddyb said you can also consider disabling heavy app activity when app is hidden (user locked screen, tapped on Home button, swiped to another app and etc.) with the help of Page Visibility API.

But it depends on your requirements of course.