Recall & Review
beginner
What is a ViewModel in Android?
A ViewModel is a class designed to store and manage UI-related data in a lifecycle conscious way. It helps data survive configuration changes like screen rotations.Click to reveal answer
beginner
How does ViewModel survive configuration changes?
ViewModel objects are tied to the lifecycle of an activity or fragment but are retained when those components are recreated during configuration changes, so data is preserved.
Click to reveal answer
intermediate
What role does ViewModelStore play in ViewModel survival?
ViewModelStore holds ViewModel instances and is retained by the system during configuration changes, allowing ViewModels to persist across activity or fragment recreation.
Click to reveal answer
intermediate
Why is it better to use ViewModel instead of onSaveInstanceState for data persistence?
ViewModel can hold complex data and live longer during configuration changes without serialization, unlike onSaveInstanceState which only saves small amounts of serializable data.
Click to reveal answer
beginner
What happens to a ViewModel when the activity is finished or destroyed permanently?
When the activity or fragment is finished and not recreated, the ViewModel is cleared and its resources are released to avoid memory leaks.
Click to reveal answer
What allows a ViewModel to survive configuration changes?
✗ Incorrect
ViewModelStore keeps ViewModels alive during configuration changes, so data is preserved.
When does the ViewModel get cleared?
✗ Incorrect
ViewModel is cleared only when the activity or fragment is finished and not recreated.
Which of these is NOT a benefit of using ViewModel?
✗ Incorrect
ViewModel does not save data to disk automatically; it holds data in memory.
What is a configuration change in Android?
✗ Incorrect
Configuration changes include screen rotations or language changes that recreate activities.
Why is ViewModel preferred over onSaveInstanceState for large data?
✗ Incorrect
onSaveInstanceState is limited to small serializable data; ViewModel can hold larger and complex data in memory.
Explain in your own words why ViewModel survives configuration changes in Android.
Think about what happens when the screen rotates and how ViewModel keeps data safe.
You got /3 concepts.
Describe the difference between ViewModel and onSaveInstanceState for handling data during configuration changes.
Consider how each method stores data and when it is restored.
You got /4 concepts.