This set of multiple-choice questions focuses on the role of the ViewModel in Android architecture, particularly in conjunction with Jetpack Compose. It explores key concepts such as state management, lifecycle handling, separation of concerns, and the use of functions like viewModel() and observeAsState() for integrating ViewModel data into Composable functions. By understanding these concepts, developers can effectively manage UI-related data, maintain consistency across configuration changes, and ensure clean separation between UI logic and data handling in their Android applications.
1.
Which of the following statements is true about the viewModel() function?
2.
Why is it important to use viewModelScope when performing background tasks?
3.
When should you use the MutableLiveData class in a ViewModel?
4.
Which of the following is a key principle of modern Android architecture recommended by Google?
5.
What dependency must be added to use the Compose viewModel() function?
6.
What is the purpose of the observeAsState() function?
7.
In a ViewModel, what triggers the recomposition of the UI?
8.
When using a ViewModel with Compose, where is the best place to initialize the ViewModel?
9.
Why is it recommended to initialize a ViewModel in a top-level Composable?
10.
Which function is used to create or access a ViewModel instance in a Composable?
11.
Which statement about MutableLiveData is correct?
12.
Which of the following best describes 'separation of concerns' in Android architecture?
13.
Which of the following is true about the viewModel() function?
14.
What is the key benefit of using ViewModel with a Compose UI?
15.
What role does the 'separation of concerns' concept play in Android app architecture?
16.
How does a ViewModel instance behave when an activity is recreated?
17.
How is a MutableState in Compose different from MutableLiveData?
18.
Which Compose library function converts a LiveData object into a State object?
19.
How does the ViewModel help with activity lifecycle management?
20.
What role does the MutableState object play in a ViewModel with Compose?
21.
What is the primary benefit of using LiveData with ViewModel in a non-Compose Android app?
22.
What is a common use case for the viewModelScope in a ViewModel?
23.
What is the primary purpose of the ViewModel component in Android architecture?
24.
Which architecture component is still relevant in modern Android app development with Compose?