Skip to content

Instantly share code, notes, and snippets.

@pfmaggi
Last active April 19, 2021 08:48
Show Gist options
  • Save pfmaggi/e28dfd937fa2efec37721d6edeedc4ea to your computer and use it in GitHub Desktop.
Save pfmaggi/e28dfd937fa2efec37721d6edeedc4ea to your computer and use it in GitHub Desktop.
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class MyWorkerFactory(private val service: UpvoteStoryHttpApi) : WorkerFactory() {
override fun createWorker(
appContext: Context,
workerClassName: String,
workerParameters: WorkerParameters
): ListenableWorker? {
// This only handles a single Worker, please don’t do this!!
// See below for a better way using DelegatingWorkerFactory
return UpvoteStoryWorker(appContext, workerParameters, DesignerNewsService)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment