1

I have a music player with a noncancellable notification. In my onDestroy, i have a clearNotification method. However when I clear the app by holding the home button and clear recent apps, the music stops but the onDestroy method is not ran because the notification doesn't clear.

So my question is, Is there any method that is ran when user clears "Recent Apps" in Android.

Web Development
  • 421
  • 1
  • 3
  • 15
  • You could try with onWindowFocusChanged() as referred to http://stackoverflow.com/questions/12478826/how-to-detect-recent-apps-system-button-clicks-honeycomb – Mithun May 11 '15 at 20:13

1 Answers1

2

It seems the best way would be to create a Service and look for the onTaskRemoved method to be called.

Look here for extensive conversation: https://android.stackexchange.com/questions/19987/what-actually-happens-when-you-swipe-an-app-out-of-the-recent-apps-list

Here's the Service API I suggest using: http://developer.android.com/reference/android/app/Service.html#onTaskRemoved%28android.content.Intent%29

Community
  • 1
  • 1
Sam Dozor
  • 40,335
  • 6
  • 42
  • 42
  • thank you worked perfectly , i was already using a service so just implemented onTaskRemoved – Web Development May 11 '15 at 20:34
  • maybe you can add this as an edit that it doesn't work unless i do=: Override public void onDestroy() { musicService.clearNotification(); super.onDestroy(); } and Override public void onServiceDisconnected(ComponentName name) { musicBound = false; musicService.clearNotification(); } – Web Development May 11 '15 at 20:46
  • interesting..so if you're clearing in `onDestroy`, what are you doing in `onTaskRemoved`? – Sam Dozor May 11 '15 at 20:47