title: How can I detect when a Cordova app has been removed from the recents menu, from within an Android plugin?
body: <p>This may seem like a strange requirement, so I will just describe what I am trying to do, and why I think I need to know when the task is removed.</p>
  
  <p>Essentially, I am trying to record the location in the background. I found a rough example of how to do so with a <code>BroadcastReceiver</code>, <a href="http://uncorkedstudios.com/blog/background-location-updates-on-android" rel="nofollow">here</a>, and I managed to implement it. I can turn it on and off programatically, from JavaScript.</p>
  
  <p>However, I am having trouble managing when it is turned off. I want to turn it off when the user swipes the main app from the recents menu, but not when the app is destroyed due to low memory.</p>
  
  <p>I can add a check in the <code>BroadcastReceiver</code> detect when the app is no longer running, but I can't detect how it was closed.</p>
  
  <p>Is there any way to detect when the app is closed in this manner?</p>
  
  <p>I found <a href="http://developer.android.com/reference/android/app/Service.html#onTaskRemoved(android.content.Intent)" rel="nofollow">onTaskRemoved()</a> but I am not sure how to use it in this case, or if it would be called after the app is destroyed due to low memory.</p>