Why different syntax to initialize a ViewModel?
So I’ve been trying to learn Android and currently studying about MVVM. So I understood that we can create ViewModels
as a bridge for the interaction between the Views
and the Models
. And in Android, we can create a ViewModel
by extending the ViewModel
class as this won’t dispose the ViewModel
on configuration changes.
And seems like the following is an incorrect way of creating a ViewModel
instance as it will create a new instance of the view model on each recomposition:
Combining user input of activity and its hosted fragment
I am developing an Android app in java using MVVM architectural pattern and Data Binding. The app has an activity which hosts two fragments (one at a time) using NavHostFragment (planning to add more different fragments in the future) each with one EditText component. The host activity has a button which is intended to confirm the user’s input from the fragment and process it.
Combining user input of activity and its hosted fragment
I am developing an Android app in java using MVVM architectural pattern and Data Binding. The app has an activity which hosts two fragments (one at a time) using NavHostFragment (planning to add more different fragments in the future) each with one EditText component. The host activity has a button which is intended to confirm the user’s input from the fragment and process it.