'What architecture should I go for do that its not a bad architecture
I have a large form to show which can not be displayed on a single page. so what we did is divide it into 7 part, each part consist of 1 fragment and all those fragments are navigated using tab layouts and view pager. each of those fragments have their on view model in order to access data binding . Now the problem is we can randomly select any tab and update data so we need a central location to store that data and update it, but the data is complex json model so can't be stored in a database easily, is there any other option to pursue?
Solution 1:[1]
If you want to centralize the data then use Activity Scoped ViewModel.
Initialized your viewmodel in your fragments as below:
private val someViewModel: SomeViewModel by activityViewModels()
OR
private val someOtherViewModel: SomeOtherViewModel by lazy {
ViewModelProvider(requireActivity()).get(SomeOtherViewModel::class.java)
}
This way you can centralize all your data manipulation or form completion at single place.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | nitinkumarp |
