title: Cordova - how to detect the app is not actively used anymore Android
body: <p>Okay, so my application is a flashlight/torch app found here:
  <a href="https://github.com/Skelware/Fancy-Flashlight" rel="nofollow">https://github.com/Skelware/Fancy-Flashlight</a> and it uses a Cordova plugin found here: <a href="https://github.com/Skelware/Cordova-Flashlight" rel="nofollow">https://github.com/Skelware/Cordova-Flashlight</a></p>
  
  <p>Currently I only care about Android. To briefly explain the way an app like this works on Android: The app has to request access to the camera and this is done in the background, it takes a while before the camera is loaded and thus loading (and unloading) should happen as little as possible. While an app has access to the camera, no other app can request access.</p>
  
  <p>When my app starts, it loads the camera and does what it needs to do. But when the user switches to a different app or closes my app, the camera is still registered to my app causing all other apps to be unable to use the camera.</p>
  
  <p>Although I would prefer to handle this on the JavaScript side, it would also be okay to handle this natively in the plugin.</p>
  
  <p>Window's unload event seems to be fired when exiting (fully exiting, that is) the app, but it doesn't have enough time to release the camera.</p>
  
  <p>Cordova version is 4.0 and Android version is 4.4, although I doubt that would matter.</p>
  
  <p>What should I do?</p>