Recall & Review
beginner
What is SavedStateHandle in Android Kotlin?
SavedStateHandle is a class that helps you save and restore UI-related data in ViewModels during process death or configuration changes, like screen rotations.Click to reveal answer
beginner
How do you get a
SavedStateHandle instance inside a ViewModel?You receive it as a constructor parameter when you create your ViewModel by extending
ViewModel and using SavedStateViewModelFactory or by viewModels() with saved state support.Click to reveal answer
beginner
How do you save a value using
SavedStateHandle?Use the
set(key, value) method. For example, savedStateHandle.set("count", 5) saves the number 5 with the key "count".Click to reveal answer
beginner
How do you retrieve a saved value from
SavedStateHandle?Use the
get<T>(key) method. For example, savedStateHandle.get<Int>("count") returns the saved integer or null if not found.Click to reveal answer
intermediate
Why is
SavedStateHandle better than just using onSaveInstanceState in Activities?SavedStateHandle works inside ViewModels, keeping UI data separate from UI controllers. It survives process death and configuration changes without cluttering Activity or Fragment code.
Click to reveal answer
What is the main purpose of
SavedStateHandle in Android Kotlin?✗ Incorrect
SavedStateHandle is designed to save and restore UI-related data inside ViewModels.
How do you typically receive a
SavedStateHandle in a ViewModel?✗ Incorrect
SavedStateHandle is passed as a constructor parameter to the ViewModel.
Which method saves a value in
SavedStateHandle?✗ Incorrect
The correct method to save data is set(key, value).
What happens to data saved in
SavedStateHandle when the app process is killed and restarted?✗ Incorrect
SavedStateHandle restores data automatically after process death.
Which Android component benefits most from using
SavedStateHandle?✗ Incorrect
SavedStateHandle is designed to be used inside ViewModels.
Explain how SavedStateHandle helps preserve UI state in Android apps.
Think about how your app remembers data after screen rotation or app restart.
You got /4 concepts.
Describe the steps to use SavedStateHandle in a ViewModel to save a counter value.
Imagine you want to keep track of a number even if the app restarts.
You got /4 concepts.