Challenge - 5 Problems
Repository Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Understanding Repository Role
What is the main purpose of the Repository pattern in Android app development?
Attempts:
2 left
💡 Hint
Think about separating data logic from UI logic.
✗ Incorrect
The Repository pattern abstracts the data sources (like databases, network, cache) and provides a clean API for the rest of the app to access data without knowing where it comes from.
❓ ui_behavior
intermediate1: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?
Attempts:
2 left
💡 Hint
LiveData is lifecycle-aware and updates observers automatically.
✗ Incorrect
LiveData observes the database and notifies the UI when data changes, so the UI updates automatically without manual refresh.
❓ lifecycle
advanced2:00remaining
Repository and ViewModel Lifecycle
Which statement best describes the lifecycle relationship between a Repository and a ViewModel in Android?
Attempts:
2 left
💡 Hint
Consider how many ViewModels might use the same data source.
✗ Incorrect
Repositories are often singleton or scoped to the application, so they can be shared and outlive ViewModels, which are tied to UI lifecycle.
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?
Attempts:
2 left
💡 Hint
Think about centralized data access and sharing.
✗ Incorrect
A shared Repository instance provides a single source of truth, enabling multiple screens to access and update data consistently without redundant reloads.
🔧 Debug
expert2: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()) } } }
Attempts:
2 left
💡 Hint
Check if the network refresh is triggered and completed before UI update.
✗ Incorrect
If refreshUsers is not called or awaited, the database is not updated, so LiveData emits old data causing UI to show outdated info.