injecting viewmodel with navigation-graph scope: NavController is not available before onCreate()
问题 I'm using a navigation-component in my application and also using shared ViewModel between multiple fragments that are in the same graph. Now I want to instantiate the ViewModel with this graph scope with this. As you know, in fragments we should inject objects ( ViewModel,..etc ) in onAttach: but when I want to do this (injecting ViewModel with a graph scope in onAttach ), this error occurs: IllegalStateException: NavController is not available before onCreate() Do you how can I do this? 回答1