Reputation: 3119
I am using a library that needs the Application class (not the application context) that I am using to work
its builder is something like Library.Builder.setApplication(app).setParameters(...).build()
is there a way to use the currently created Application in Hilt? @ApplicationContext obviously does not work
Upvotes: 1
Views: 3104
Reputation: 629
Simply inject the Application class:
class MyClass @Inject constructor(
private val application: Application,
)
Upvotes: -1
Reputation: 167
I'm not 100% sure, but maybe you can cast Application Context to Application class. I had similar problem when I needed Activity instance in provides method. I cast Activity Context from Hilt annotations and it works.
Upvotes: 6