0
0
Android Kotlinmobile~20 mins

Repository pattern 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
What 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.
ATo store user preferences and settings only.
BTo directly connect UI components to the database without any abstraction.
CTo handle all UI animations and transitions in the app.
DTo separate data access logic from UI logic, making code easier to manage and test.
Attempts:
2 left
💡 Hint
Think about how to keep your app organized and easy to change.
ui_behavior
intermediate
1:30remaining
How 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?
AThe UI automatically updates because LiveData observes the data changes from the Repository.
BThe UI must be manually refreshed by the user to see new data.
CThe Repository directly modifies UI elements to show new data.
DThe app crashes because Repository cannot notify the UI.
Attempts:
2 left
💡 Hint
Think about how LiveData helps UI react to data changes.
lifecycle
advanced
2:00remaining
What lifecycle benefit does the Repository pattern provide in Android apps?
How does using a Repository help manage data during configuration changes like screen rotations?
ARepository only works with static data and ignores lifecycle events.
BRepository resets all data when the screen rotates, forcing a reload.
CRepository keeps data consistent and survives configuration changes, avoiding unnecessary reloads.
DRepository causes memory leaks during lifecycle changes.
Attempts:
2 left
💡 Hint
Think about how ViewModel and Repository work together during rotations.
navigation
advanced
2:00remaining
How should the Repository pattern be used with Navigation components?
When navigating between fragments, how does the Repository pattern help with data sharing?
ARepository provides a single source of truth that multiple fragments can access for consistent data.
BEach fragment should create its own Repository instance with separate data.
CRepository should be tightly coupled to navigation actions to control screen changes.
DRepository replaces the Navigation component to handle screen transitions.
Attempts:
2 left
💡 Hint
Consider how to share data easily between screens.
🔧 Debug
expert
2:30remaining
What 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:
ANo error; the UI will just not update.
BNullPointerException because data is null and cannot be observed.
CIllegalStateException because LiveData must be initialized before observing.
DClassCastException because LiveData type is incorrect.
Attempts:
2 left
💡 Hint
What happens if you call a method on a null object in Kotlin?