Gabor Varadi
1 min readJun 28, 2020

--

Direct reference to Context from a ViewModel is a problem because ViewModel outlives the Context's lifecycle. However, this context argument here isn't stored in the ViewModel, it's a parameter that will only be used inside the Activity. The NavController access works by the same principle, and also does not leak, despite having a smaller lifecycle.

--

--

Gabor Varadi
Gabor Varadi

Written by Gabor Varadi

Android dev. Zhuinden, or EpicPandaForce @ SO. Extension function fan #Kotlin, dislikes multiple Activities/Fragment backstack.

No responses yet