I already tried a JobService as well, but I get the same result, as with the JobIntentService, namely my Notification gets called after x seconds when the app is running in the foreground, but not after swiping the app in the recent task area.
Here is how I start the JobIntentService from my Fragment:
Intent serviceIntent = new Intent(getActivity(), AlertJob.class);
serviceIntent.putExtra("inputExtra", timeForAlarm);
AlertJob.enqueueWork(getContext(), serviceIntent);
And this is my JobIntentService Class:
public class AlertJob extends JobIntentService {
public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, AlertJob.class, 123, work);
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
protected void onHandleWork(@NonNull Intent intent)
{
try
{
Thread.sleep(5000);
startService(new Intent(getApplicationContext(), Service_Notification.class));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public boolean onStopCurrentWork() {
return super.onStopCurrentWork();
}
}
I have already tried the AlarmManager and so on as well, but the problem remains the same. The JobIntentService gets destroyed when the app is only running in the background.
Thank you very much for your help!