Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 3 MCQs Advanced Networking with Retrofit

CSE227 — Advanced Android App Development 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Retrofit Basics and Integration Easy

    What is Retrofit primarily used for in Android development?

  2. Question 2 of 60 Retrofit Basics and Integration Easy

    Which company is the creator of the Retrofit library?

  3. Question 3 of 60 Retrofit Basics and Integration Easy

    What is the main purpose of the Retrofit.Builder class?

  4. Question 4 of 60 Retrofit Basics and Integration Easy

    To integrate Retrofit into a Gradle-based Android project, which section of the build.gradle file do you add its dependency to?

  5. Question 5 of 60 Handling API Requests Easy

    In Retrofit, what does the @GET annotation signify?

  6. Question 6 of 60 Handling API Requests Easy

    How are API endpoints defined in Retrofit?

  7. Question 7 of 60 Handling API Requests Easy

    What is the purpose of the @Path annotation in a Retrofit interface method?

  8. Question 8 of 60 Handling API Requests Easy

    If you want to add a URL parameter like ?sort=new, which Retrofit annotation would you use?

  9. Question 9 of 60 Parsing and Displaying Data Easy

    Which of the following is a popular JSON parsing library often used with Retrofit as a converter?

  10. Question 10 of 60 Parsing and Displaying Data Easy

    In the context of using Retrofit with a JSON API, what is the role of a data class (or POJO)?

  11. Question 11 of 60 Parsing and Displaying Data Easy

    What is the purpose of GsonConverterFactory.create() when building a Retrofit instance?

  12. Question 12 of 60 Parsing and Displaying Data Easy

    Which Android UI component is most commonly used to display a list of items fetched from an API?

  13. Question 13 of 60 Parsing and Displaying Data Easy

    To automatically parse a JSON object into a Kotlin data class, the variable names in the data class should typically match what?

  14. Question 14 of 60 Asynchronous Networking Easy

    Which method on a Retrofit Call object is used to execute a network request asynchronously?

  15. Question 15 of 60 Asynchronous Networking Easy

    What is the main reason for making network requests asynchronously in an Android app?

  16. Question 16 of 60 Asynchronous Networking Easy

    When using Kotlin Coroutines with Retrofit, what keyword is added to an interface method to make it a non-blocking function?

  17. Question 17 of 60 Authentication Easy

    What is the most common and scalable way to add a dynamic authentication token to every request made with Retrofit?

  18. Question 18 of 60 Authentication Easy

    Which HTTP header is conventionally used to send an API token for authentication, often prefixed with "Bearer"?

  19. Question 19 of 60 Authentication Easy

    In a Retrofit API interface, the @Header annotation is used for what purpose?

  20. Question 20 of 60 Handling API Requests Easy

    Which annotation is used to send a complete object as the request body, typically for an HTTP POST or PUT request?

  21. Question 21 of 60 Retrofit Basics and Integration Medium

    When configuring a Retrofit.Builder, you add multiple Converter.Factory instances, first GsonConverterFactory and then MoshiConverterFactory. Which converter will Retrofit attempt to use first for response parsing?

  22. Question 22 of 60 Retrofit Basics and Integration Medium

    You are setting up a Retrofit instance. Consider the following code:
    kotlin
    val retrofit = Retrofit.Builder()
    .addConverterFactory(GsonConverterFactory.create())
    .build()
    val apiService = retrofit.create(ApiService::class.java)

    What essential component is missing for this instance to make a successful network request to https://api.example.com/users?

  23. Question 23 of 60 Retrofit Basics and Integration Medium

    In the context of Retrofit, what is the primary role of defining an interface with annotations like @GET and @POST?

  24. Question 24 of 60 Retrofit Basics and Integration Medium

    Why would a developer explicitly provide a custom OkHttpClient to the Retrofit.Builder using .client(myOkHttpClient)?

  25. Question 25 of 60 Handling API Requests Medium

    Given the Retrofit interface method:
    kotlin
    @GET("group/{id}/users")
    fun groupList(@Path("id") groupId: Int, @Query("sort") sort: String): Call<List<User>>

    If you call this method with groupList(42, "desc"), what will be the resulting relative URL?

  26. Question 26 of 60 Handling API Requests Medium

    When sending data in the body of a POST request, what is the key difference between using the @Body and @Field annotations in a Retrofit interface?

  27. Question 27 of 60 Handling API Requests Medium

    Your app needs to send a unique, dynamically generated X-Request-ID header with each API call. Which Retrofit annotation is the most appropriate for this purpose when the ID changes for every call?

  28. Question 28 of 60 Handling API Requests Medium

    You need to make a POST request to an endpoint that expects data in application/x-www-form-urlencoded format. Which combination of annotations is required on your Retrofit interface method?

  29. Question 29 of 60 Handling API Requests Medium

    If you use the @Url annotation in a Retrofit interface method parameter, what is a key requirement for the endpoint definition in the annotation (e.g., @GET)?

  30. Question 30 of 60 Parsing and Displaying Data Medium

    You are using GsonConverterFactory and your API returns a JSON object. If a field exists in the JSON response but is not defined in your corresponding Kotlin data class, what is the default behavior of Gson?

  31. Question 31 of 60 Parsing and Displaying Data Medium

    The API returns a JSON with a field named "first_name". Your Kotlin data class has a property named firstName. How can you correctly map this field using Gson without changing the property name in your data class?

  32. Question 32 of 60 Parsing and Displaying Data Medium

    An API endpoint /users returns a JSON array of user objects, like [ { "id": 1, "name": "Alice" }, { "id": 2, "name": "Bob" } ]. What should be the return type of the corresponding method in your Retrofit interface?

  33. Question 33 of 60 Parsing and Displaying Data Medium

    What is the most appropriate use case for creating a custom Gson TypeAdapter and registering it with your Retrofit instance?

  34. Question 34 of 60 Asynchronous Networking Medium

    In Retrofit, which statement correctly compares call.execute() and call.enqueue()?

  35. Question 35 of 60 Asynchronous Networking Medium

    What is the primary advantage of defining a Retrofit service method as a suspend fun for use with Kotlin Coroutines, compared to the traditional Call<T> with enqueue()?

  36. Question 36 of 60 Asynchronous Networking Medium

    When using call.enqueue(callback), if the server responds with an HTTP status code of 404 (Not Found), which part of the Callback will be executed?

  37. Question 37 of 60 Asynchronous Networking Medium

    When using a suspend function in a Retrofit interface, how should you handle potential network errors like a timeout or no internet connectivity?

  38. Question 38 of 60 Authentication Medium

    What is the most common and maintainable way to add an Authorization: Bearer <token> header to every request made through a single Retrofit instance?

  39. Question 39 of 60 Authentication Medium

    Your application uses an OAuth 2.0 access token that expires. When a request fails with a 401 Unauthorized error, you need to use a refresh token to get a new access token and then retry the original request. Which OkHttp component is best suited for implementing this logic?

  40. Question 40 of 60 Authentication Medium

    You need to add a static API key as a query parameter (e.g., ?api_key=YOUR_KEY) to all requests made by Retrofit. Which is the most efficient and cleanest approach?

  41. Question 41 of 60 Retrofit Basics and Integration Hard

    You have configured a Retrofit instance with two custom Converter.Factory implementations, FactoryA and FactoryB, added in that order: retrofitBuilder.addConverterFactory(FactoryA).addConverterFactory(FactoryB). FactoryA can handle TypeX but returns null from its responseBodyConverter method for TypeY. FactoryB can handle TypeY. If you make an API call defined as fun getData(): Call<TypeY>, what will be the outcome?

  42. Question 42 of 60 Authentication Hard

    In a multithreaded application, multiple concurrent API calls fail with a 401 Unauthorized error, triggering your custom Retrofit Authenticator. A naive implementation of the authenticate() method immediately calls the token refresh endpoint. What is the primary race condition this approach creates, and what is the correct way to solve it?

  43. Question 43 of 60 Asynchronous Networking Hard

    Consider the following Kotlin Coroutines code within a ViewModel: viewModelScope.launch { val userDeferred = async { api.getUser() }; val postsDeferred = async { api.getPosts() }; try { val user = userDeferred.await(); val posts = postsDeferred.await(); } catch (e: Exception) { // handle error } }. If the api.getPosts() call fails with an IOException but api.getUser() completes successfully before the failure, what is the state of the viewModelScope's Job and what happens to the result of api.getUser()?

  44. Question 44 of 60 Handling API Requests Hard

    You need to implement a file upload using a @Multipart request. The API requires a JSON object and a file to be sent in the same request. How should you define the RequestBody for the JSON part to ensure it is correctly formatted with Content-Type: application/json?

  45. Question 45 of 60 Parsing and Displaying Data Hard

    An API endpoint returns a JSON array of 'events'. Each event object has a "type" field ("message" or "image") and other fields that differ based on the type. How would you model this polymorphic data using Moshi and a custom JsonAdapter.Factory for seamless parsing into a sealed class Event?

  46. Question 46 of 60 Authentication Hard

    You have implemented a Retrofit Authenticator to refresh a JWT. The token refresh endpoint itself is protected and requires the expired token to be passed for validation. What critical step must you take when creating the OkHttpClient for the refresh API call inside the authenticate() method to avoid an infinite loop?

  47. Question 47 of 60 Retrofit Basics and Integration Hard

    A Retrofit service method is defined with a dynamic URL: suspend fun getFile(@Url fileUrl: String): ResponseBody. The base URL of the Retrofit instance is https://api.example.com/v1/. If you call this method with getFile("images/logo.png"), what will be the final request URL, and why?

  48. Question 48 of 60 Asynchronous Networking Hard

    When defining a Retrofit service interface with suspend functions, what is the fundamental difference in error handling between a function returning Response<T> versus one returning just T when the server responds with an HTTP error code like 404 or 500?

  49. Question 49 of 60 Handling API Requests Hard

    An API requires you to send a DELETE request with a JSON body. Which combination of Retrofit annotations would you use to define this service method?

  50. Question 50 of 60 Parsing and Displaying Data Hard

    An API for a specific field sometimes returns a JSON object {"key":"value"} and other times returns an empty JSON array [] to signify 'no data'. A standard Gson/Moshi parser would crash with a type mismatch. What is the most robust way to handle this using a custom adapter?

  51. Question 51 of 60 Retrofit Basics and Integration Hard

    What is the primary purpose of a Retrofit CallAdapter.Factory, and in which scenario is creating a custom one absolutely necessary?

  52. Question 52 of 60 Authentication Hard

    If your Authenticator's authenticate() method returns null, what is the direct consequence for the original request that received the 401 and for any other requests that were queued by OkHttp while the authenticator was running?

  53. Question 53 of 60 Handling API Requests Hard

    Consider a Retrofit method: fun search(@Query("q") query: String?, @Query("sort") sort: String = "asc"). How does Retrofit handle a null value passed for the query parameter, and how does it handle the default value for the sort parameter if it's not provided by the caller?

  54. Question 54 of 60 Parsing and Displaying Data Hard

    When using the Gson converter, you have a data class with a lateinit var property. The corresponding field is missing from the JSON response. What will be the outcome during deserialization?

  55. Question 55 of 60 Asynchronous Networking Hard

    You are using Flow with Retrofit to implement a real-time search feature. A code snippet in your ViewModel is: searchQuery.debounce(300).flatMapLatest { query -> flow { emit(api.search(query)) } }.catch { ... }. If a user types quickly, causing a new query to be emitted while a previous api.search() call is still in flight, what does flatMapLatest ensure?

  56. Question 56 of 60 Retrofit Basics and Integration Hard

    If you add a HttpLoggingInterceptor as a network interceptor (addNetworkInterceptor) versus an application interceptor (addInterceptor), how does the logged Request object differ when a request is redirected by the server (e.g., a 301 response)?

  57. Question 57 of 60 Handling API Requests Hard

    What is the key difference between using @QueryMap with a Map<String, String> and using multiple @Query annotations in a Retrofit service method?

  58. Question 58 of 60 Authentication Hard

    When securing API keys used by your Retrofit/OkHttp client in an Android app, which method provides the strongest protection against static analysis and reverse engineering of the APK?

  59. Question 59 of 60 Asynchronous Networking Hard

    You make a suspend Retrofit call inside a coroutine launched with supervisorScope. If the network call fails with an IOException, how does this exception affect the supervisorScope and its other child coroutines?

  60. Question 60 of 60 Retrofit Basics and Integration Hard

    When building an OkHttpClient, you can set timeouts using connectTimeout, readTimeout, and callTimeout. If you set a callTimeout of 30 seconds and a readTimeout of 15 seconds, and a server takes 20 seconds to send a response, what will happen?

That's unit 3

Answer a few questions and your score shows up here.