I have set a work manager to do task at specific time periodically. But It is working with other android version like 25 or lower. When I run it on API 28 It is going to stop firing a broadcast when I clear app from recent lists.
I have scheduled work manager like this in activity :
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(MyWorker.class).setInitialDelay(15, TimeUnit.SECONDS).build();
WorkManager.getInstance().enqueue(mywork);
This is my Worker class :
public class MyWorker extends Worker {
@NonNull
@Override
public Worker.WorkerResult doWork() {
// Do the work here
Mylogger.getInstance().printLog("MyWorr","doWork()");
//fire broadcast from here
Intent broadcastIntent = new Intent(getApplicationContext(), TimeMatchingBroadcastReceiver.class);
getApplicationContext().sendBroadcast(broadcastIntent);
CommonUtils.scheduleWorkManager();
// Indicate success or failure with your return value:
return WorkerResult.SUCCESS;
// (Returning RETRY tells WorkManager to try this task again
// later; FAILURE says not to try again.)
}
}
I want execute work manager even when I close or clear app from recent list on all version of android. Thanks.