Hilt: Injection not working in BroadcastReceiver
See original GitHub issueThe issue is described on Stackoverflow https://stackoverflow.com/questions/62335727/hilt-injection-not-working-with-broadcastreceiver
I am not the poster, but I did encounter the same issue.
This workaround prevented the crash:
override fun onReceive(context: Context, intent: Intent?) {
val injector = BroadcastReceiverComponentManager.generatedComponent(context) as AppBroadcastReceiver_GeneratedInjector
injector.injectAppBroadcastReceiver(UnsafeCasts.unsafeCast(this))
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:14 (1 by maintainers)
Top Results From Across the Web
Hilt Injection not working with BroadcastReceiver
How it works internally: Hilt creates abstract class for @AndroidEntryPoint annotated component(Activity, Fragment, BroadcastReceiver etc) and ...
Read more >Dependency injection with Hilt | Android Developers
Hilt is a dependency injection library for Android that reduces the boilerplate of doing manual dependency injection in your project.
Read more >Migration to Dagger Hilt, what the guides are missing - Medium
BroadcastReceiver not being injected 🤦 Injection happens in the parent's onReceive() method, however the method is abstract and we can't call ...
Read more >A Standard Way to Implement Dependency Injection in Android
BroadcastReceiver. Inject dependencies into non-Android classes. Even though Hilt supports most of the Android classes, at some point, you'll need ...
Read more >The practical guide – Part 4: Dependency injection with Hilt
How to fix this? One thing you can think of is by creating some class where you handle all the dependencies there (Like...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another workaround is to use a class like this:
Now extend this class instead of
BroadcastReceiver
and you can callsuper.onReceive()
.Fix : So basically, I had
I moved the code in another method
and voilà!