-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to inject WorkManager? #419
Comments
You'll want to use a https://developer.android.com/reference/androidx/work/WorkerFactory to return your injected instances. Same pattern as what's suggested for fragments in the doc. |
@evant Could you please provide a more detailed explanation of how to do this using the kotlin-inject library? Unfortunately, I couldn't figure it out no matter how hard I tried. |
Hi, I just migrated an Android project from Hilt to kotlin-inject. This is a summary of the code I used to inject WorkManager
Then provide WorkerFactory to your application class:
And don't forget to disable WorkManager initialization from your Manifest. I hope it helps. |
Thank you so much @AdriaBosch, just a little note though. For me it wouldn't compile until I changed @Provides
@IntoMap
fun provideMyWorkerEntry(
workerCreator: (context: Context, params: WorkerParameters) -> MyWorker,
): Pair<KClass<out ListenableWorker>, (Context, WorkerParameters) -> MyWorker> {
return Pair(MyWorker::class, workerCreator)
} into @Provides
@IntoMap
fun provideMyWorkerEntry(
workerCreator: (context: Context, params: WorkerParameters) -> MyWorker,
): Pair<KClass<out ListenableWorker>, (Context, WorkerParameters) -> **ListenableWorker**> {
return Pair(MyWorker::class, workerCreator)
} Even though
|
Hello.
I can't find how to inject WorkManager after searching the documentation.
Could you please tell me how to do this and update the documentation?
The text was updated successfully, but these errors were encountered: