Skip to content

Instantly share code, notes, and snippets.

@Ikhiloya
Last active May 26, 2020 14:37
Show Gist options
  • Select an option

  • Save Ikhiloya/25f1b0d199c8d57e14d0bd8d8c6ee016 to your computer and use it in GitHub Desktop.

Select an option

Save Ikhiloya/25f1b0d199c8d57e14d0bd8d8c6ee016 to your computer and use it in GitHub Desktop.
A worker class to post person data to the remote server
val periodicSyncDataWork =
PeriodicWorkRequest.Builder(PersonWorker::class.java, 15, TimeUnit.MINUTES)
.addTag(Constant.TAG_SYNC_PERSON)
.setConstraints(constraints) // setting a backoff on case the work needs to retry
.setBackoffCriteria(
BackoffPolicy.LINEAR,
PeriodicWorkRequest.MIN_BACKOFF_MILLIS,
TimeUnit.MILLISECONDS
).build()
getWorkManager()!!.enqueueUniquePeriodicWork(
Constant.SYNC_PERSON_WORK_NAME,
ExistingPeriodicWorkPolicy.KEEP, //Existing Periodic Work policy
periodicSyncDataWork //work request
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment