Android recently introduced Architecture Components and, in particular, ViewModel , which
designed to store and manage data associated with the user interface, so that the data saves configuration changes, such as screen shielding
In the example provided by Google, ViewModel is used as follows:
public class MyActivity extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
MyViewModel model = ViewModelProviders.of(this).get(MyViewModel.class);
model.getUsers().observe(this, users -> {
});
}
}
Question: What does the ViewModel look like for correlation with data binding ?
I mean that in the case of data binding there will be bindingone that provides data for the user interface.
Would it look like this:
...
model.getUsers().observe(this, users -> {
});
...
source
share