Android Development Android Networking 2 — Questions and Answers
Question 1: Which Kotlin library is commonly paired with Retrofit for asynchronous network calls using coroutines?
- kotlinx.coroutines (Correct answer)
- RxJava
- AsyncTask
- HandlerThread
Correct answer: kotlinx.coroutines
Kotlinx.coroutines integrates with Retrofit via suspend functions, enabling clean asynchronous networking without callbacks.
Question 2: What HTTP status code indicates a successful response?
- 200 (Correct answer)
- 404
- 500
- 301
Correct answer: 200
HTTP status code 200 (OK) indicates the request was successful and the server returned the expected response.
Question 3: Which Retrofit annotation is used to send a POST request body as JSON?
- @Body (Correct answer)
- @Field
- @Part
- @Json
Correct answer: @Body
@Body annotation in Retrofit designates a parameter as the request body, which is serialized using the configured converter.
Question 4: What is the purpose of the NetworkSecurityConfig in Android?
- To define trusted Certificate Authorities and network security policies (Correct answer)
- To configure WiFi settings
- To manage VPN connections
- To set firewall rules
Correct answer: To define trusted Certificate Authorities and network security policies
NetworkSecurityConfig allows you to customize network security settings like trusted CAs, cleartext traffic, and certificate pinning via XML.
Question 5: Which library is used for efficient image loading from URLs in Android apps?
- Glide
- Picasso
- Coil
- All of the above (Correct answer)
Correct answer: All of the above
Glide, Picasso, and Coil are all popular Android image loading libraries that handle downloading, caching, and displaying images from URLs.
Question 6: What does certificate pinning protect against in Android networking?
- Man-in-the-middle attacks using fraudulent certificates (Correct answer)
- SQL injection attacks
- Replay attacks on APIs
- Brute force authentication
Correct answer: Man-in-the-middle attacks using fraudulent certificates
Certificate pinning ensures the app only trusts specific server certificates, preventing man-in-the-middle attacks using rogue CAs.
Which Kotlin library is commonly paired with Retrofit for asynchronous network calls using coroutines?