0
0
Android Kotlinmobile~10 mins

Why ViewModel survives configuration changes in Android Kotlin - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a ViewModel instance in an Activity.

Android Kotlin
val viewModel = ViewModelProvider(this).get([1]::class.java)
Drag options to blanks, or click blank then click option'
AApplication
BMainActivity
CViewModelProvider
DMyViewModel
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the Activity class instead of the ViewModel class.
2fill in blank
medium

Complete the code to extend the ViewModel class correctly.

Android Kotlin
class MyViewModel : [1]() {
  // ViewModel logic here
}
Drag options to blanks, or click blank then click option'
AActivity
BFragment
CViewModel
DApplication
Attempts:
3 left
💡 Hint
Common Mistakes
Extending Activity or Fragment instead of ViewModel.
3fill in blank
hard

Fix the error in the code to get the ViewModel in a Fragment.

Android Kotlin
val viewModel = ViewModelProvider([1]).get(MyViewModel::class.java)
Drag options to blanks, or click blank then click option'
ArequireActivity()
Bthis
Capplication
DviewLifecycleOwner
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'this' which refers to Fragment, creating a Fragment-scoped ViewModel.
4fill in blank
hard

Fill both blanks to explain why ViewModel survives configuration changes.

Android Kotlin
ViewModel is stored in the [1] and tied to the [2] lifecycle.
Drag options to blanks, or click blank then click option'
AViewModelStore
BActivity
CApplication
DFragment
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing Application with ViewModelStore or Fragment.
5fill in blank
hard

Fill all three blanks to complete the explanation of ViewModel behavior.

Android Kotlin
When configuration changes, the [1] is destroyed but the [2] and [3] remain, keeping ViewModel alive.
Drag options to blanks, or click blank then click option'
AActivity
BViewModelStore
CFragment
DApplication
Attempts:
3 left
💡 Hint
Common Mistakes
Thinking Activity survives configuration changes.