3

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:

  1. 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 recents onTaskRemoved is not called.
  2. If switching from Service to JobIntentService and starting this service via JobIntentServiceLauncher.enqueueWork then almost immediately the OnAppRemovedFromRecentListener is destroyed and onTaskRemoved 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?

peemes
  • 165
  • 1
  • 7

1 Answers1

0

If you use a activity , i think you can use onDestroy() or onStop() methods to detect cleanup or closing of app properly

Abhishek Mathur
  • 478
  • 5
  • 12
  • I want to handle it also beyond the activity - for example when exited from app by back button, then all activities are destroyed but process still works and is available on 'recents'. So relaying on activity onDestrop and onStop is not enough :( – peemes Jan 31 '18 at 09:31