How Do I Store A Data From A Fragment So It Can Be Reuse In A Mvvm Architecture?
I have know that an Activity/Fragment has to create a ViewModel, and the ViewModel can be created from a ViewModelFactory. And the ViewModel itself are using a data repository whic
Solution 1:
you need to use a shared viewModel, a ViewModel that is shared between your fragments and survives navigating between certain fragments. Implementation depends on what you use in your project. you can create a ViewModel in the activity and access them from your fragments and put the shared data in this ViewModel. or if you are using navigation component you can have a shared ViewModel per nav graph. and with dagger and koin you can define a costume scope for your ViewModel to survive. see these links:
Share data between fragmentsShare data between fragments with shared viewModel
Post a Comment for "How Do I Store A Data From A Fragment So It Can Be Reuse In A Mvvm Architecture?"