The BEST android courses in the world: codingwithmitch.com/
In this video I show you how to do dependency injection into viewmodels using Hilt. In the previous video I showed you how to do field injection into an activity. Constructor injection is preferable over field injection whenever possible because then you know exactly what a class needs to be built.
Hilt makes it very easy to instantiate viewmodels in Fragments and activities. You can use the "by viewmodels()" method to maintain a viewmodel instance in a fragment. Or use the "by activityViewModels()" method to maintain a viewmodel instance between multiple fragments sharing the same host activity.
Code: github.com/mitchtabian/MVVMRe...
Follow me:
Instagram: / codingwithmitch
Twitter: / mitch_tabian
.
.
Негізгі бет Ғылым және технология Hilt ViewModels and Dependency Injection
Пікірлер: 116