Until now (before Android Oreo) I was handling removing from app recents via Service.onTaskRemoved()
, like:
public class OnAppRemovedFromRecentListener extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_NOT_STICKY;
}
@Override
public void onTaskRemoved(Intent rootIntent) {
super.onTaskRemoved(rootIntent);
// there I am handling removing from recents
}
}
but now when I run app on Android Oreo I'am unable to achieve the same behaviour in any way. Tried 2 approaches:
- If still using
Service
then service is desroyed after some time of inactivity when app is in background and then if user removes app from recentsonTaskRemoved
is not called. - If switching from
Service
toJobIntentService
and starting this service viaJobIntentServiceLauncher.enqueueWork
then almost immediately the OnAppRemovedFromRecentListener is destroyed andonTaskRemoved
is also not called when app is removed from recents
Does anybody know way how to detect removing my app from recents on Android Oreo which will work always?