COURSE 7: WORKING WITH DATA IN ANDROID QUIZ ANSWERS
Week 2: Interaction with REST APIs in Android
Meta Android Developer Professional Certificate
Complete Coursera Answers & Study Guide
Enroll in Coursera Meta Android Developer Professional Certification
INTRODUCTION
Practice applying asynchronous programming techniques to query REST APIs and handle their responses using Kotlin and Android.
Learning Objectives
- Work with JSON data in Kotlin
- Explain different HTTP methods, status codes and responses.
- Explain concurrency in Kotlin
- Apply Kotlin coroutines in Android applications
- Apply different concurrency patterns
SELF REVIEW: HTTP REQUEST/RESPONSE IN KOTLIN
1. In this exercise, which scope was used to launch the fetchContent method?
- lifecycleScope (CORRECT)
- ktorScope
- activityScope
Correct! The lifecycleScope is default scope for each Activity.
2. In this exercise, which library was used to make network request?
- HttpClient
- fetch
- MutableLiveData
- ktor (CORRECT)
Correct! The library used to make network request is called ktor. It provides the HttpClient class.
3. In this exercise, which class was used to make a network request?
- MutableLiveData
- ktor
- HttpClient (CORRECT)
Correct! The class used to make network request is called HttpClient. It is provided by the ktor library.
4. Using HTTPS over HTTP is preferable because?
- HTTPS is a faster protocol than HTTP.
- HTTPS is encrypted and more secure than HTTP (CORRECT)
- HTTPS can transfer JSON objects while HTTP cannot.
- Ktor only knows how to work with HTTPS, not HTTP.
That’s correct. HTTPS is an encrypted and secure networking protocol, while HTTP is a clear text protocol.
5. In Ktor, the body() function is used to return what?
- A typed copy of the HTTP response (CORRECT)
- A string with the body of the HTTP response
- A JSON object of the HTTP response
- The elements of the HTTP body response list
That’s correct. The body function is used to convert a response string to a Kotlin object.
KNOWLEDGE CHECK: HTTP IN KOTLIN
1. Ktor is an HTTP networking library. True or false?
- True (CORRECT)
- False
Correct! Ktor library allows you to make HTTP requests and handle responses.
2. HTTP requests are made of which of these items? Select all that apply.
- Headers (CORRECT)
- Body (CORRECT)
- Operation type (CORRECT)
- Target path (CORRECT)
- Version of the protocol (CORRECT)
Correct! The headers are part of HTTP request.
Correct! The body is part of HTTP request.
Correct! The operation type is part of HTTP request.
Correct! The target path is part of HTTP request.
Correct! The version of the protocol is part of HTTP request.
3. Which HTTP response status code represents the operation success?
- 200 (CORRECT)
- 404
- 500
Correct! The 200 status code means operation success.
4. Which HTTP response status code represents the resource not found?
- 200
- 404 (CORRECT)
- 500
Correct! The 404 status code means resource not found.
5. HTTP request headers provide the target path as part of HTTP request. True or false?
- True
- False (CORRECT)
Correct! The HTTP request headers provide additional information to the server about the operation being executed.
6. HTTP headers are present in which of these items? Select all that apply:
- Protocol
- Body
- Response (CORRECT)
- Request (CORRECT)
Correct! Both request and response may provide additional metadata in form of headers.
Correct! Both request and response may provide additional metadata in form of headers.
7. What does this server response represent?
HTTP/1.1 200 OK
Date: Sun, 10 Oct 2010 15:16:01 GMT
Server: Apache
Content-length: 18532
Content-type: text/html
- Operation Error
- Undefined operation result
- Operation success (CORRECT)
Correct! The HTTP status code 200 represents operation success.
8. Which library can be used can you use in an Android app to make network requests?
- HttpClient
- Ktor (CORRECT)
- compose
Correct! The library that can be used to make network request is ktor.
SELF REVIEW: PARSING DATA IN KOTLIN
1. In this exercise, what was the name of the method that downloaded the menu items?
- fetchMenu
- retrieveMenu
- getMenu (CORRECT)
Correct! The name of the method was getMenu.
2. In this exercise, how was the value from menuItemsLiveData retrieved?
- Using the getValue method
- Using the observeAsState method (CORRECT)
- Using the value property
Correct! The value from menuItemsLiveData was retrieved using observeAsState method with emptyList as the default parameter.
3. In this exercise the menuItemsLiveData.value was assigned at the main thread. True or false?
- True (CORRECT)
- False
Correct! The menuItemsLiveData.value was assigned at the main thread using runOnUiThread.
4. Which of the following statements about JSON are correct? Select all that apply.
- JSON can be used to store data (CORRECT)
- JSON can only be used for mobile applications.
- JSON is specific to JavaScript
- JSON can be used to transfer data between a client and a server (CORRECT)
That’s correct. Data can be stored within JSON objects as key-value pairs.
That’s right! JSON is a data interchange format used for data transfer.
5. Which function of GSON would you call to convert a JSON string to a Kotlin object?
- gson.fromJson (CORRECT)
- Gson.fromJson
- gson.toJson
- Gson.toJson
That’s correct! fromJson will parse a JSON string into a Kotlin object.
KNOWLEDGE CHECK
1. Image caching reduces the amount of data that needs to be downloaded from an external source. True or false?
- False
- True (CORRECT)
Correct! Caching allows for the reuse of images, which can reduce the amount of data that needs to be downloaded from an external source and speed up the app.
2. Which of these are Android image loading libraries? Select all that apply.
- Coil (CORRECT)
- Glide (CORRECT)
- Rembrandt
- Picasso (CORRECT)
- Ktor
Correct! Coil is an Android image loading library.
Correct! Glide is an Android image loading library.
Correct! Picasso is an Android image loading library.
3. Which of these can the Glide library take care of? Select all that apply.
- Managing the image cache (CORRECT)
- Sending an HTTP request to an external source and retrieving an image response. (CORRECT)
- Managing memory (CORRECT)
Correct! The Glide library can take care of managing an image cache.
Correct! The Glide library can take care of making HTTP requests and handling HTTP responses.
Correct! The Glide library can take care of managing memory.
4. Which library can be used to parse JSON data in Kotlin?
- LiveData
- Ktor (CORRECT)
- Glide
Correct! The Ktor library allows you to parse JSON data by using serializer.
5. Before JSON data can be used in the app, it should be serialized. True or false?
- True (CORRECT)
- False
Correct! It is much easier to work with Kotlin objects if serialization is performed before working with the data.
MODULE QUIZ: INTERACTING WITH REST APIS IN ANDROID
1. Which protocol should you use for making HTTP network requests?
- HTTP
- HTTPS (CORRECT)
- HTTP or HTTPS
That’s right. HTTPS is a secure protocol and should be the only protocol you use to make HTTP network requests.
2. What is the Ktor Client primarily used for? Select all that apply.
- Logging network traffic
- Reading network responses as Kotlin objects (CORRECT)
- Converting JSON to Kotlin objects
- Making network requests (CORRECT)
That’s right. Ktor Client makes it easy to read network request responses as Kotlin objects.
That’s right. Ktor Client is a library for making network requests.
3. What threads should you use for making a network request and for updating the UI?
- The main thread for both making network requests and updating the UI
- A background thread for network requests, the main thread for updating the UI (CORRECT)
- The main thread for network requests, a background thread for updating the UI
- Background threads for both making network requests and updating the UI
That’s right. Network requests are long-running operations and should be executed on a background thread. The UI should be updated on the main thread.
4. What is the right syntax for making a GET HTTP request using Ktor? Select all that apply.
- Ktor.get(“https://…”)
- client.request(“https://…”) { method = HttpMethod.Get } (CORRECT)
- client.get(“https://…”) (CORRECT)
- client.post(“https://…”)
That’s right. Calling “request” and setting the method to HttpMethod.Get is one way to make a GET HTTP request.
That’s right. Calling “get” is one way to make a GET HTTP request.
5. JSON has some key advantages as a data format. Which of the below are strengths of JSON? Select all that apply.
- It is concise and therefore lightweight (CORRECT)
- It can express data other formats cannot
- It is easy to read as a string
- It is widely supported (CORRECT)
That’s right. JSON expresses data in a very minimalistic way.
That’s right. JSON is supported by all common languages, including Kotlin and JavaScript.
6. You have the JSON string “{\”name\”:\”Jake\”}” and the Kotlin object Person that has a name field. Using GSON, how would you parse the string to the Person object?
- val person: Person = gson.fromJson(“{\”name\”:\”Jake\”}”)(CORRECT)
- val person: Person = Gson.fromJson(“{\”name\”:\”Jake\”}”)
- val person = gson.fromJson(“\”name\”:\”Jake\”}”, Person::class.java)
That’s right. This is how you would parse the JSON string into a Person object.
7. What is Glide used for? Select all that apply.
- Resize images so they consume less memory (CORRECT)
- Making network requests
- Parsing JSON responses as images
- Downloading images from presenting them on screen (CORRECT)
That’s right. Glide can resize images for you.
That’s right. Glide is a library that makes image loading from servers easier.
8. Which composable would you use to download images with the Glide library?
- GlideImage composable (CORRECT)
- Bitmap composable
- Image composable
Correct! GlideImage composable is used to download images within a Compose app.
9. Which ktor class is used to make HTTP request and handle HTTP response?
- Client
- HttpClient (CORRECT)
- KtorClient
Correct! The HttpClient class is used to make HTTP requests and handle HTTP responses.
10. Name the data format contained in this code.
{
"Appetizers": {
"menu": [
"Spinach Artichoke Dip",
"Hummus",
"Fried Calamari Rings",
"Fried Mushrooms"
]
}
}
- Binary
- JSON (CORRECT)
- XML
Correct! This is the JSON data format.
CONCLUSION
TWB
Subscribe to our site
Get new content delivered directly to your inbox.
Quiztudy Top Courses
Popular in Coursera
- Meta Marketing Analytics Professional Certificate.
- Google Digital Marketing & E-commerce Professional Certificate.
- Google UX Design Professional Certificate.
- Meta Social Media Marketing Professional Certificate
- Google Project Management Professional Certificate
- Meta Front-End Developer Professional Certificate
Liking our content? Then, don’t forget to ad us to your BOOKMARKS so you can find us easily!