Created
March 31, 2020 16:31
-
-
Save pfmaggi/4a552f180be55706874be1cdf11dddf5 to your computer and use it in GitHub Desktop.
Code for the Medium article: "Customizing WorkManager"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Copyright 2020 Google LLC. | |
| SPDX-License-Identifier: Apache-2.0 */ | |
| class MyWorkerFactory(private val service: DesignerNewsService) : WorkerFactory() { | |
| override fun createWorker( | |
| appContext: Context, | |
| workerClassName: String, | |
| workerParameters: WorkerParameters | |
| ): ListenableWorker? { | |
| return when(workerClassName) { | |
| UpvoteStoryWorker::class.java.name -> | |
| ConferenceDataWorker(appContext, workerParameters, service) | |
| 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