Skip to content

Instantly share code, notes, and snippets.

@pfmaggi
Created March 31, 2020 17:50
Show Gist options
  • Save pfmaggi/09eba1063902af5a66e0bfe2d3686c08 to your computer and use it in GitHub Desktop.
Save pfmaggi/09eba1063902af5a66e0bfe2d3686c08 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 */
class ConferenceDataWorkerFactory(
private val refreshEventDataUseCase: RefreshConferenceDataUseCase
) : WorkerFactory() {
override fun createWorker(
appContext: Context,
workerClassName: String,
workerParameters: WorkerParameters
): ListenableWorker? {
return when (workerClassName) {
ConferenceDataWorker::class.java.name ->
ConferenceDataWorker(appContext, workerParameters, refreshEventDataUseCase)
else ->
// Return null, so that the base class can delegate to the default WorkerFactory.
null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment