When a user switches to another application on a mobile device AIR on mobile applications keep running. It continues to hold on to resources, fire off events, and has the potential to use power draining resources like network calls, or geolocation if your app makes use of them.
That’s why one of the first tips you see is to kill or tombstone your application when the user switches away from it. In general, unless you have a good reason to do not do this, you should. Your users might not notice that you drain their battery to zero, but then again they might.
But I have a good reason for not wanting to do this right away. Actually I have a few:
- As a user, I frequently accidentally hit the home instead of back button
- As a user, I frequently lookup stuff on the web then come back to an application.
- As a developer, I frequently makes calls to OS resources like the camera or mapping in my app.
All these add up to needing to revisit closing on exit.
I’d like to get the benefit of closing on exit in terms of resource usage, but I’d like a grace period. So, my solution, fire off an event when a user leaves the application, that sets a timer to shut down the app. Then if the user returns, kill that timer.
Simple, easy, and best of both worlds.