github-commit-browser
github-commit-browser copied to clipboard
[Question] - How to dynamically set the bundle from AbstractSavedStateViewModelFactory
Hello @Nimrodda ,
I've the same DI setup as you, everything works like a charm, but I was wondering, what if we would like to dynamically put some values inside the bundle (from AbstractSavedStateViewModelFactory) to be used inside the ViewModel - let's say I want to catch something from getIntent() or getArguments() and forward it through the bundle - how would you implement it?
Thanks once again.
You mean provide default values when the ViewModel is created by the factory? I haven't used it myself, but if I remember correctly it should be possible. I have an example here.
Another method would be not to store it in the Bundle and instead just use standard Dagger constructor injection to pass the values that you want to the ViewModel constructor.
Yes our module can provide a provideDefaultArgs but I was thinking in something in runtime. Imagine we have a ListActivity and a DetailActivity and when we touch an item we want to pass that item (or an ID to be fetched in SharedPrefs/Room) to the DetailActivity ViewModel through the bundle. Makes sense my idea? ^^
We probably need to "Assist Inject" that bundle right?