Android Development Android Networking 1 — Questions and Answers
Question 1: Which library is commonly used for type-safe HTTP client calls in Android?
- Retrofit (Correct answer)
- Volley
- OkHttp
- HttpURLConnection
Correct answer: Retrofit
Retrofit turns HTTP API calls into Kotlin/Java interfaces with annotations, providing type-safe REST client functionality.
Question 2: What annotation is used in Retrofit to define a GET HTTP request?
- @GET (Correct answer)
- @HttpGet
- @Request(GET)
- @GetRequest
Correct answer: @GET
@GET annotates a Retrofit interface method to indicate it should make an HTTP GET request to the specified URL path.
Question 3: Which class in OkHttp is used to intercept and observe HTTP calls?
- Interceptor (Correct answer)
- NetworkCallback
- HttpObserver
- RequestFilter
Correct answer: Interceptor
OkHttp's Interceptor interface allows you to observe, modify, or short-circuit HTTP requests and responses.
Question 4: What permission is required for an Android app to access the internet?
- android.permission.INTERNET (Correct answer)
- android.permission.NETWORK
- android.permission.ACCESS_NETWORK
- android.permission.ONLINE
Correct answer: android.permission.INTERNET
The android.permission.INTERNET permission must be declared in AndroidManifest.xml for an app to make network requests.
Question 5: Which Retrofit converter factory parses JSON responses using Gson?
- GsonConverterFactory (Correct answer)
- JsonConverterFactory
- GsonParser
- RetrofitGson
Correct answer: GsonConverterFactory
GsonConverterFactory is added to a Retrofit.Builder to enable automatic serialization and deserialization of JSON using Gson.
Question 6: What does the term REST stand for in the context of Android networking?
- Representational State Transfer (Correct answer)
- Remote Execution State Transfer
- Resource Exchange Standard Transfer
- Reliable Endpoint Service Transfer
Correct answer: Representational State Transfer
REST (Representational State Transfer) is an architectural style for building scalable web services using standard HTTP methods.
Which library is commonly used for type-safe HTTP client calls in Android?