So I want to know when the app swipes the app from the recents list, dismissing it: This is the code I had regarding this on devices until 8. But a normal Service cannot start in the background. I tried using a JobScheduler, but onTaskRemoved is not being called for a JobScheduler (Neither the normal one, or the the ones that come with the Firebase JobDispatcher.
public class OnClearFromRecentService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("ClearFromRecentService", "ClearFromRecentService Service Started");
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i("ClearFromRecentService", "ClearFromRecentService Service Destroyed");
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Log.e("ClearFromRecentService", "ClearFromRecentService END");
//Code here
}
}
How I start service:
try {
startService(new Intent(PSApplicationClass.this, OnClearFromRecentService.class));
} catch (Exception e) {
Utils.appendLog("Error trying to start OnClearFromRecentService: " + e.getMessage(), "E", Constants.OTHER);
}
Error:
OTHER Error trying to start OnClearFromRecentService: Not allowed to start service Intent { cmp=nl.hgrams.passenger/.services.OnClearFromRecentService }: app is in background uid UidRecord{9531e38 u10a172 RCVR idle change:uncached procs:1 seq(0,0,0)}