0
0
Android Kotlinmobile~10 mins

Why architecture scales codebases 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 declare a ViewModel class in Kotlin.

Android Kotlin
class MainViewModel : [1]() {
    // ViewModel logic here
}
Drag options to blanks, or click blank then click option'
AViewModel
BFragment
CActivity
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using Activity or Fragment instead of ViewModel.
Confusing Service with ViewModel.
2fill in blank
medium

Complete the code to observe LiveData in an Activity.

Android Kotlin
viewModel.data.observe([1]) { value ->
    // update UI with value
}
Drag options to blanks, or click blank then click option'
Athis
BlifecycleOwner
CviewLifecycleOwner
Dcontext
Attempts:
3 left
💡 Hint
Common Mistakes
Using viewLifecycleOwner which is for Fragments.
Passing lifecycleOwner without context.
3fill in blank
hard

Fix the error in the repository pattern code by completing the interface declaration.

Android Kotlin
interface [1] {
    fun getUser(id: String): User
}
Drag options to blanks, or click blank then click option'
AUserDataSource
BUserViewModel
CUserService
DUserRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Naming it UserViewModel which is for UI logic.
Using UserService which is more network related.
4fill in blank
hard

Fill both blanks to complete the ViewModel factory code for dependency injection.

Android Kotlin
class [1](private val repository: [2]) : ViewModel() {
    // ViewModel code
}
Drag options to blanks, or click blank then click option'
AMainViewModel
BUserRepository
CUserService
DMainActivity
Attempts:
3 left
💡 Hint
Common Mistakes
Using MainActivity as class name instead of ViewModel.
Injecting UserService directly instead of repository.
5fill in blank
hard

Fill all three blanks to complete the Kotlin code for a simple MVVM data flow.

Android Kotlin
class [1](private val [2]: [3]) : ViewModel() {
    val data = MutableLiveData<String>()
}
Drag options to blanks, or click blank then click option'
AUserViewModel
Brepository
CUserRepository
DMainActivity
Attempts:
3 left
💡 Hint
Common Mistakes
Using MainActivity as class name.
Naming the repository parameter incorrectly.