Delayed Work
Typically, we are happy to have our work begin right away, if the conditions allow it. Occasionally, we may want to intentionally delay that work for a bit.
For this, you can call setInitialDelay()
on the OneTimeWorkRequest.Builder
as part of configuring the work. There are two flavors of setInitialDelay()
:
- one takes a
long
value and aTimeUnit
, where theTimeUnit
indicates what unit of measure thelong
is in (e.g.,TimeUnit.SECONDS
) - one takes a
Duration
, which is part of Java 8 and only available on API Level 26 and higher
In either case, the work will be delayed by at least that amount of time. However, depending on circumstances (constraints, Doze mode, etc.), the work might happen substantially later than the delay period. Do not assume that your work will start immediately after your delay period.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.