I'm trying to update my simple android app to use Dagger2. I think I've managed to understand some of the basics and the basic stuff (activities, view models, helpers) are being created through it.
Now, there's still a small gotcha: the app has a button that, when pressed, must schedule a job service. I can refactor my jobservice so that its dependencies are passed through its constructor, but how do I instantiate it from my activity? In other words, how do I replace this code:
val serviceComponent = ComponentName(getApplication(), DbUpdaterJob::class.java)
var jobInfo = JobInfo.Builder(DB_UPDATER_JOB_ID, serviceComponent)
.setRequiredNetworkType(networkType)
.setPersisted(true)
.build()
val scheduler = getApplication<Application>().getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
val res = scheduler.schedule(jobInfo)
so that instantiation is relegated to dagger?
Thanks!