我在单独的模块中定义了自己的 LayoutInflater.Factory2 类。我想将它注入到我的应用程序中的每个活动中,但重点是我必须在活动的 super.onCreate() 方法之前设置这个工厂。 当我使用 Hilt 时,它会在 super.onCreate() 之后立即进行注入。所以我有一个 UninitializedPropertyAccessException。
有没有机会在 super.onCreate 之前使用 Hilt 进行注入?
以下是我的模块 di 示例。
@Module
@InstallIn(SingletonComponent::class)
object DynamicThemeModule {
@FlowPreview
@Singleton
@Provides
fun provideDynamicThemeConfigurator(
repository: AttrRepository
): DynamicTheme<AttrInfo> {
return DynamicThemeConfigurator(repository)
}
}