question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inject into Workers (androidx.WorkManager API)

See original GitHub issue

Hi, from latest Google I/O you just presented the new androidx.work.Worker class, part of the new WorkManager API.

Since the Worker class is created by the framework (we only pass the Worker class type to the WorkManager), how can we @inject fields into the Worker ? Do you intend to add a new AndroidInjection.inject() function that takes a worker as argument ?

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:85
  • Comments:43 (1 by maintainers)

github_iconTop GitHub Comments

101reactions
ronshapirocommented, May 15, 2018

We hope to have something soon. It likely will be in a new artifact (dagger-android-work), plus support for @ContributesAndroidInjector.

31reactions
autonomousappscommented, May 31, 2018

I know this is the wrong repo for this comment, but I wonder aloud why they couldn’t have created a WorkerFactory class similar to ViewModelProvider.Factory for defining how to create Worker objects. Or something. I just really don’t understand why Android framework classes can never have useful public constructors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inject into Workers (androidx.WorkManager API) - Medium
Step 1: Create AndroidWorkerInjection.class Responsible for injecting dependencies into [WorkManager API](https://developer.android.com/topic/ ...
Read more >
Getting started with WorkManager - Android Developers
To get started using WorkManager, first import the library into your Android project. Add the following dependencies to your app's build.gradle file:.
Read more >
Dagger 2 setup with WorkManager - ProAndroidDev
​Setup our existing code base with AssistedInject is simple. Annotate Worker class with @AssistedInject . Any parameters that we want to create with...
Read more >
How to inject Worker class? - android - Stack Overflow
When I try to inject updater worker to main activity, I get this error: Dagger does not support injecting @AssistedInject type, .workmanager.
Read more >
Android WorkManager Worker can not be injected using ...
Add kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha01' to your app's build.gradle and it should work.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found