0
0
Android Kotlinmobile~20 mins

Repository pattern in depth in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Repository Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Repository Role
What is the main purpose of the Repository pattern in Android app development?
ATo abstract data sources and provide a clean API for data access
BTo manage network requests directly in the UI layer
CTo handle UI rendering and user interactions
DTo store UI state and lifecycle events
Attempts:
2 left
💡 Hint
Think about separating data logic from UI logic.
ui_behavior
intermediate
1:30remaining
Repository and LiveData Interaction
Given a Repository that returns LiveData from a Room database, what happens in the UI when the database data changes?
AThe UI automatically updates because LiveData notifies observers of changes
BThe UI crashes because LiveData cannot be observed
CThe UI must manually refresh data by calling the Repository again
DThe UI shows stale data until the app restarts
Attempts:
2 left
💡 Hint
LiveData is lifecycle-aware and updates observers automatically.
lifecycle
advanced
2:00remaining
Repository and ViewModel Lifecycle
Which statement best describes the lifecycle relationship between a Repository and a ViewModel in Android?
AThe Repository is destroyed before the ViewModel to free resources
BThe Repository typically outlives the ViewModel and can be shared across multiple ViewModels
CThe ViewModel and Repository have the same lifecycle and are always created and destroyed together
DThe Repository is recreated every time the ViewModel is accessed
Attempts:
2 left
💡 Hint
Consider how many ViewModels might use the same data source.
navigation
advanced
2:00remaining
Repository Impact on Navigation Flow
How does using a Repository pattern affect navigation between screens that share data in an Android app?
AIt prevents data sharing and requires passing data via intents only
BIt forces each screen to reload data independently, causing delays
CIt allows screens to share data easily by accessing the same Repository instance
DIt causes navigation to fail if the Repository is not passed explicitly
Attempts:
2 left
💡 Hint
Think about centralized data access and sharing.
🔧 Debug
expert
2:30remaining
Debugging Repository Data Inconsistency
You notice your UI shows outdated data even though the Repository fetches fresh data from the network. Which is the most likely cause?
Android Kotlin
class UserRepository(private val api: ApiService, private val dao: UserDao) {
  val users = dao.getUsersLiveData()

  suspend fun refreshUsers() {
    val response = api.fetchUsers()
    if (response.isSuccessful) {
      dao.insertUsers(response.body() ?: emptyList())
    }
  }
}
AThe dao.insertUsers method does not insert data into the database
BThe LiveData from dao.getUsersLiveData() does not notify observers on database changes
CThe API fetchUsers method returns cached data instead of fresh data
DThe refreshUsers function is not called or awaited properly, so data is not updated in the database
Attempts:
2 left
💡 Hint
Check if the network refresh is triggered and completed before UI update.