Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created December 26, 2019 20:52
Show Gist options
  • Save Lavanyagaur22/659b07bab466896e8ab32fc958b782d2 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/659b07bab466896e8ab32fc958b782d2 to your computer and use it in GitHub Desktop.
private fun scheduleRepeatingTasks() {
/*Setting up different constraints on the work request.
*/
val constraints = Constraints.Builder().apply {
setRequiredNetworkType(NetworkType.CONNECTED)
setRequiresCharging(true)
setRequiresStorageNotLow(true)
}.build()
/*Build up an obejct of PeriodicWorkRequestBuilder
*/
val repeatingWork = PeriodicWorkRequestBuilder<NotificationRequestWorker>(
1,
TimeUnit.DAYS
).setConstraints(constraints)
.build()
/*Enqueue the work request to an instance of Work Manager
*/
WorkManager.getInstance(this).enqueue(repeatingWork)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment