Challenge - 5 Problems
Repository Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateWhat is the main purpose of the Repository pattern in Android development?
Choose the best explanation for why developers use the Repository pattern in Android apps.
Attempts:
2 left
💡 Hint
Think about how to keep your app organized and easy to change.
✗ Incorrect
The Repository pattern acts as a middle layer between data sources and the UI, helping to keep code clean and testable.
❓ ui_behavior
intermediateHow does the Repository pattern affect UI updates when data changes?
In an Android app using LiveData and Repository, what happens when data in the repository changes?
Attempts:
2 left
💡 Hint
Think about how LiveData helps UI react to data changes.
✗ Incorrect
LiveData observes data in the Repository and notifies UI components to update automatically.
❓ lifecycle
advancedWhat lifecycle benefit does the Repository pattern provide in Android apps?
How does using a Repository help manage data during configuration changes like screen rotations?
Attempts:
2 left
💡 Hint
Think about how ViewModel and Repository work together during rotations.
✗ Incorrect
Repository combined with ViewModel keeps data stable across lifecycle changes, improving performance.
advanced
How should the Repository pattern be used with Navigation components?
When navigating between fragments, how does the Repository pattern help with data sharing?
Attempts:
2 left
💡 Hint
Consider how to share data easily between screens.
✗ Incorrect
A shared Repository allows fragments to access the same data source, ensuring consistency during navigation.
🔧 Debug
expertWhat error occurs if Repository returns null LiveData and UI tries to observe it?
Given this Kotlin code snippet, what error will happen?
val data: LiveData? = repository.getData()
data.observe(viewLifecycleOwner) { value -> println(value) }
Options:
Attempts:
2 left
💡 Hint
What happens if you call a method on a null object in Kotlin?
✗ Incorrect
Observing a null LiveData causes a NullPointerException because you cannot call observe on null.
