Search code examples
android-viewmodeldagger-hiltandroid-jetpack-navigation

Is there a way to pass an argument from NavHostController to ViewModel?


How can i pass an argument from NavHostController to my ViewModel init{}?


Solution

  • I don't really understand how is the SQL query related here. To pass an argument from your navigation arguments to a viewmodel you have to use SavedStateHandle. Then you can use get() or getLiveData(). The key would be equal to the argument name. https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate