0
0
Android Kotlinmobile~10 mins

Why network calls fetch remote data in Android Kotlin - Test Your Understanding

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

Complete the code to start a network call using Kotlin coroutines.

Android Kotlin
GlobalScope.launch {
    val response = [1]("https://example.com/data.json")
}
Drag options to blanks, or click blank then click option'
AfetchData
BfetchFromNetwork
CfetchRemoteData
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that does not exist or is not standard.
Trying to call a network function without coroutine scope.
2fill in blank
medium

Complete the code to convert the network response to a string.

Android Kotlin
val data = response.[1]()
Drag options to blanks, or click blank then click option'
AreadText
BtoString
CtoJson
DtoByteArray
Attempts:
3 left
💡 Hint
Common Mistakes
Using toString() which does not read the content but returns object info.
Using toJson() which is not a standard function.
3fill in blank
hard

Fix the error in the code to make the network call on the main thread safe.

Android Kotlin
runBlocking {
    val result = withContext([1]) {
        fetch("https://example.com")
    }
}
Drag options to blanks, or click blank then click option'
ADispatchers.Main
BDispatchers.IO
CDispatchers.Default
DDispatchers.Unconfined
Attempts:
3 left
💡 Hint
Common Mistakes
Using Dispatchers.Main which blocks the UI.
Using Dispatchers.Default which is for CPU-intensive tasks.
4fill in blank
hard

Fill both blanks to create a simple function that fetches remote data and returns it as a string.

Android Kotlin
suspend fun getData(url: String): String {
    return withContext([1]) {
        val response = fetch(url)
        response.[2]()
    }
}
Drag options to blanks, or click blank then click option'
ADispatchers.IO
BDispatchers.Main
CreadText
DtoString
Attempts:
3 left
💡 Hint
Common Mistakes
Using Dispatchers.Main which blocks UI.
Using toString() which does not read response content.
5fill in blank
hard

Fill all three blanks to create a coroutine that fetches data and updates the UI safely.

Android Kotlin
GlobalScope.launch {
    val data = withContext([1]) {
        fetch("https://api.example.com")
            .[2]()
    }
    withContext([3]) {
        textView.text = data
    }
}
Drag options to blanks, or click blank then click option'
ADispatchers.IO
BreadText
CDispatchers.Main
DtoString
Attempts:
3 left
💡 Hint
Common Mistakes
Updating UI on IO dispatcher causing crashes.
Not reading response content properly.