I study Android WorkManager, and fond one problem.
I have 2 Works, first of them fetch some data from server and second preload resources (depends on result of first work). I need doing this chains one time per hour.
I need something like:
workManager.beginWith(work1).then(work2)
But in WorkManger API I found chain only for OneTimeWorkRequest.
Given that the repetition interval is in reality a minimum interval, WorkManager makes available an additional parameter that you can use to specify a window where Android can execute your Work.
A WorkRequest for repeating work. This work executes multiple times until it is cancelled, with the first execution happening immediately or as soon as the given Constraints are met.
You cannot chain PeriodicWorkRequest
s. For your use-case you might consider using a OneTimeWorkRequest
with a Worker
that enqueues a copy of itself at the end of doWork()
with an initial delay (to simulate periodicity).
That way you can still do chaining. I would tag all work requests consistently so you can getWorkInfosByTagLiveData()
correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With