Reputation: 25
I want to get AndroidContext for Koin in Java. In Kotlin I would call androidContext() in startKoin block https://insert-koin.io/docs/reference/koin-android/dsl/
But in Java I start Koin in this way
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
KoinApplication koin = KoinAndroidApplication
.create(this)
.modules(KoinInjectorKt.getKoinInjector());
startKoin(koin);
}
}
and I there is no androidContext() function in KoinAndroidApplication
Upvotes: 2
Views: 1348
Reputation: 1300
According to KDoc
KoinAndroidApplication.create(..)
Create Koin Application with Android context - For Java compat
It's already using androidContext
under the hood(when you call KoinAndroidApplication.create(this)
), if you open sources of the KoinAndroidApplication
you will see:
object KoinAndroidApplication {
/**
* Create Koin Application with Android context - For Java compat
*/
@JvmStatic
@JvmOverloads
fun create(context: Context, androidLoggerLevel: Level = Level.INFO): KoinApplication {
return KoinApplication.init().androidContext(context).androidLogger(androidLoggerLevel)
}
}
Upvotes: 2