Junior — Middle
How does the view (presentation) receive data updates from the model?
sobes.tech AI
Answer from AI
In Android architecture, View receives updates from the model (for example, from LiveData or StateFlow) through observers. The model contains data and notifies subscribers of changes, allowing the View to automatically update the UI.
For example, when using LiveData:
viewModel.someLiveData.observe(viewLifecycleOwner) { data ->
// update UI based on new data
textView.text = data
}
Thus, the View subscribes to data changes in the model and reacts to them, ensuring reactive interface updates without the need to manually poll the model.