https://kotlinlang.org logo
t

the great warrior

06/05/2023, 1:41 AM
Greetings, folks. Here RescheduleAlarmWorker and AlarmWorker factories are provided by the ClockWorkerFactory class. And the issue is that the ClockWorkerFactory class only adds the first factory to its delegate when initializing itself, but it does not add the second factory.
Copy code
@HiltAndroidApp
class ClockApplication : Application(), Configuration.Provider {

    @Inject lateinit var clockWorkerFactory: ClockWorkerFactory
    override fun getWorkManagerConfiguration(): Configuration =
        Configuration.Builder()
            .setMinimumLoggingLevel(android.util.Log.DEBUG)
            .setWorkerFactory(clockWorkerFactory)
            .build()
}
@Singleton
class ClockWorkerFactory @Inject constructor(
    alarmRepository: AlarmRepository,
    scheduleAlarmManager: ScheduleAlarmManager,
    alarmNotificationHelper: AlarmNotificationHelper,
    mediaPlayerHelper: MediaPlayerHelper,
) : DelegatingWorkerFactory() {
    init {
        addFactory(RescheduleAlarmWorkerFactory(alarmRepository, scheduleAlarmManager))
        addFactory(AlarmWorkerFactory(alarmRepository, alarmNotificationHelper, mediaPlayerHelper))
    }
}
not kotlin but kotlin colored 2
a

Android Mahi

06/05/2023, 2:24 AM
Used named annotation to denote to hilt there are two distinct classes needs to be injected
t

the great warrior

06/05/2023, 9:36 PM
can you please give me an example ?