Skip to content

Instantly share code, notes, and snippets.

@pfmaggi
Created March 31, 2020 18:46
Show Gist options
  • Save pfmaggi/151e81e94ddb95d34d4d4aec0581f5d0 to your computer and use it in GitHub Desktop.
Save pfmaggi/151e81e94ddb95d34d4d4aec0581f5d0 to your computer and use it in GitHub Desktop.
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
private fun scheduleFetchEventData() {
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val conferenceDataWorker = OneTimeWorkRequestBuilder<ConferenceDataWorker>()
.setInitialDelay(MINIMUM_LATENCY, TimeUnit.SECONDS)
.setConstraints(constraints)
.build()
val operation = WorkManager.getInstance(this)
.enqueueUniqueWork(
uniqueConferenceDataWorker,
ExistingWorkPolicy.KEEP,
conferenceDataWorker)
.result
operation.addListener(
{ Timber.i("ConferenceDataWorker enqueued..") },
{ it.run() }
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment