Sampada Sampada - 1 year ago 67
Android Question

Notify when an app has been removed from the recent apps list

I want to show up a notification when my app is removed from the recent apps list. I've tried putting code for that in

but neither works .
is called as soon as the app is closed (though it is still in the recent app list). Can anyone tell which method is called when app is removed from recent app list or any way in which this need can be accomplished ?

Answer Source

When you swipe your app out of Recents, its task get killed instantly. No lifecycle methods will be called.

To get notified when your app getting swiped out of Recents, you could start a sticky Service and override its onTaskRemoved() method.

From the documentation of onTaskRemoved():

This is called if the service is currently running and the user has removed a task that comes from the service's application. If you have set ServiceInfo.FLAG_STOP_WITH_TASK then you will not receive this callback; instead, the service will simply be stopped.