question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use @ViewModelInject on a NavGraph-scoped ViewModel?

See original GitHub issue

If there is only ApplicationComponent, ActivityComponent, ActivityRetainedComponent and FragmentComponent, then how do I get a NavGraph-scoped ViewModel with @ViewModelInject from a NavBackStackEntry?

Sounds like this would only work if there’s a custom component definition and the NavBackStackEntry counts as a @AndroidEntryPoint, but that doesn’t seem possible. Just a hunch, though, in the sample I’m looking at I’m not even sure why @ViewModelInject works at all, or how to get additional @Assisted parameters that are not the SavedStateHandle.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Chang-Ericcommented, Jun 2, 2020

Just FYI, we’re going to come back to this issue about Hilt after the official launch. Thanks for filing it though and sorry for the wait!

0reactions
Zhuindencommented, Jun 3, 2020

Nice, now I understand Hilt. Cheers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A step by step guide on how to use Nav-graph Scoped ...
In this article, I will show you how to share viewmodels between fragments in Google's proposed MVVM with a single Activity. WARNING:I won't...
Read more >
Hilt creating different instances of view model inside same ...
When you use by viewModels , you are creating a ViewModel scoped to that individual Fragment - this means each Fragment will have...
Read more >
How can I create a ViewModel using Hilt which is scoped to ...
I noticed that with Hilt, ViewModels using @ViewModelInject are ... I'm only scoping viewModels using the Nav-graph Scoped ViewModels.
Read more >
Hilt ViewModels and Dependency Injection - YouTube
... courses in the world: https://codingwithmitch.com/In this video I show you how to do dependency injection into viewmodels using Hilt.
Read more >
Gabor Varadi on Twitter: "NavGraph-scoped ViewModels (for ...
NavGraph-scoped ViewModels (for those who are using Jetpack Navigation) was announced since June 2019, yet most often I still see people scoping their ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found