The only way to get the current activity context i...
# koin
j
The only way to get the current activity context is using parameters when it is being injected?
t
You could also use a scope providing it. But eventually it'd be best to not provide it as a dependency.
j
the problem I have is I need the activity context to get the colorPrimary attribute
t
So you basically need the theme. Might be a bit safer to inject.
j
The problem is theme is changing
So I guess androidContext() is getting the app context, which has AppThemeOne, but I was changing the theme later to AppThemeTwo, but androidContext() can't know that
t
You could wrap everything with a color provider you use in the UI where you have the
Context
You're right,
androidContext()
binds the
Application
j
But I will have the same problem if I keep using androidContext() for this colorProvider
Should be great to have a way to get the activity context out of the box
t
I didn't mean to use the
Context
within the provider, but rather have the provider implement
(Context) -> Int
The you just call
colorProvider(context)
from where you actually have the context.
Using the
Activity
as dependency is dangerous and discouraged by many. That's why I don't mind that it doesn't exist.
If your dependencies are bound to this activity, it should be fairly easy to create a scope and inject the activity there. Like that instance might not leak.
j
I will take a look, thank you 🙂
👍 1