I am using WorkManager to schedule both periodic and one-time work, and I am tagging all of the work with the same tag so that I can identify it later:
workRequestBuilder.addTag("mywork");
With various work items enqueued, at various times in the future, I would like a way of querying the work queue to determine when the next work is scheduled to run for this particular tag ("mywork"). Yes, I know that it will not be exact and will be subject to Doze etc, but it would still be useful to know when -- in the absence of other factors -- the work is likely to run.
I know how to query the work queue and pick out enqueued work items as follows, but I'm just not sure how to tell what time each work item is scheduled to run:
WorkManager workManager = WorkManager.getInstance();
ListenableFuture<List<WorkInfo>> workInfos = workManager.getWorkInfosByTag("mywork");
try {
List<WorkInfo> workInfoList = workInfos.get();
for (WorkInfo workInfo : workInfoList) {
WorkInfo.State state = workInfo.getState();
if (state == WorkInfo.State.ENQUEUED) {
UUID workerId = workInfo.getId();
Log.d(TAG, "found enqueued work with id " + workerId);
// BUT HOW DO I TELL WHAT TIME THIS WORK IS SCHEDULED TO RUN?
}
}
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
from WorkManager get time of next scheduled work by tag
No comments:
Post a Comment