0
0
Android Kotlinmobile~10 mins

Room with Coroutines in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a suspend function for inserting a user in the DAO.

Android Kotlin
suspend fun insertUser(user: User) [1]
Drag options to blanks, or click blank then click option'
A= insert(user)
B{ /* implementation */ }
C= suspendInsert(user)
D= insertUser(user)
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to assign a function call without suspend keyword.
Using a non-suspend function call inside a suspend function without proper handling.
2fill in blank
medium

Complete the DAO function to return all users as a Flow.

Android Kotlin
@Query("SELECT * FROM users")
fun getAllUsers(): [1]
Drag options to blanks, or click blank then click option'
AFlow<List<User>>
BLiveData<List<User>>
CDeferred<List<User>>
DList<User>
Attempts:
3 left
💡 Hint
Common Mistakes
Using List which is synchronous and not reactive.
Using LiveData instead of Flow when working with coroutines.
3fill in blank
hard

Fix the error in the suspend DAO function declaration for deleting a user.

Android Kotlin
suspend fun deleteUser(user: User) [1]
Drag options to blanks, or click blank then click option'
A{ delete(user) }
B= delete(user)
C= suspendDelete(user)
D{ suspendDelete(user) }
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to assign a function call without suspend keyword.
Using an undefined suspendDelete function.
4fill in blank
hard

Fill both blanks to define a suspend function that updates a user in the DAO.

Android Kotlin
suspend fun updateUser(user: User) [1] update(user) [2]
Drag options to blanks, or click blank then click option'
A{
B}
Csuspend
Dfun
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting curly braces causing syntax errors.
Trying to use 'suspend' or 'fun' inside the function body.
5fill in blank
hard

Fill all three blanks to create a DAO function that returns a Flow of users filtered by age.

Android Kotlin
@Query("SELECT * FROM users WHERE age [1] :minAge")
fun getUsersOlderThan(minAge: Int): [2] = [3]
Drag options to blanks, or click blank then click option'
A>
BFlow<List<User>>
Cflow { emitAll(query(minAge)) }
DList<User>
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator like '<'.
Returning List instead of Flow>.
Not returning a Flow implementation.