I have the following one-time worker.
// Create a Constraints that defines when the task should run Constraints constraints = new Constraints.Builder() .setRequiredNetworkType(NetworkType.UNMETERED) .setRequiresBatteryNotLow(true) // Many other constraints are available, see the // Constraints.Builder reference .build(); OneTimeWorkRequest oneTimeWorkRequest = new OneTimeWorkRequest.Builder(SyncWorker.class) .setConstraints(constraints) .addTag(SyncWorker.TAG) .build();
According to https://developer.android.com/topic/libraries/architecture/workmanager
// (Returning RETRY tells WorkManager to try this task again // later; FAILURE says not to try again.)
I was wondering, if SyncWorker
keep returning RETRY
, what is the retry strategy of WorkManager
? For instance, what is the maximum retry count for WorkManager
? The documentation isn't clear on this.
To create a set of constraints and associate it with some work, create a Constraints instance using the Contraints. Builder() and assign it to your WorkRequest. Builder() .
androidx.work.OneTimeWorkRequest. A WorkRequest for non-repeating work. OneTimeWorkRequests can be put in simple or complex graphs of work by using methods like WorkManager. beginWith or WorkManager. beginWith .
Use WorkManager for reliable workWorkManager is intended for work that is required to run reliably even if the user navigates off a screen, the app exits, or the device restarts. For example: Sending logs or analytics to backend services. Periodically syncing application data with a server.
The setBackoffCriteria is used for when you need to specify at which rate to retry if the Work fails.
The default is BackoffPolicy.EXPONENTIAL
. We only retry when you ask us to RETRY
by returning WorkerResult.RETRY
or when constraints that were required for your Worker
are now unmet. So for e.g. if you required a NETWORK
constraint, and now the device lost its active Network
connection - then the Worker
will be stopped and be automatically retried (when the constraints are met).
For more information look at the docs.
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