I have to initialize WorkerManager not only once because at Runtime some arguments may change (WorkerFactory()). So I need to call
val configuration = Configuration.Builder()
.setWorkerFactory(aggregatingWorkerFactory)
.build()
WorkManager.initialize(context!!, configuration)
However, calling it second time throws IllegalStateException.
I read that I can initialize it on ContentProvider: https://medium.com/@programmerr47/custom-work-manager-initialization-efdd2afa6459 but my workerFactory object is injected by dagger and I couldn't use AndroidInjector on Content Provider, because it was always not initialized:
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property androidInjector has not been initialized
I read here that there is an interface HasContentProviderInjector
:
but I cannot find it in my Dagger2 version 2.24 and I don't believe it should work, because If I understand correctly ContentProvider is created before Application object.
What should I do? Try to clear by reflection objects:
sDelegatedInstance != null && sDefaultInstance != null
or sth else?