I have a very strange problem with Compose and Application class. I'm accesing the applicationContext of my custom Application class on the init block of the first viewmodel of the first screen on the first activity of the app,
and it's returning null. I'm initializing it on the Application's onCreate method. It can be a problem related with Compose. Supposedly Application's onCreate is
Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created
class CustomApplication: Application() {
lateinit var container: AppContainer
lateinit var context: Context
override fun onCreate() {
super.onCreate()
container = AppContainer()
context = applicationContext
}
}
I get the Application object using this:
fun CreationExtras.CustomApplication(): CustomApplication=
(this[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY] as CustomApplication)