Android Week 7 Part 2

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards

What is Retrofit?

a type-safe HTTP client for Android and Java that simplifies interacting with REST APIs by handling request/response serialization and supporting common HTTP operations.

2
New cards

What is the Retrofit class used for?

acilitates network operations and is the main entry point for making HTTP requests.

3
New cards

What is a Converter Factory in Retrofit?

converts JSON or other data formats into POJOs (Plain Old Java Objects) and vice versa. GsonConverterFactory is commonly used for JSON conversion.

4
New cards

What is a Call object in Retrofit?

represents an HTTP request and is used to execute network requests and receive responses.

5
New cards

What is a Callback in Retrofit?

handles network responses asynchronously.

6
New cards

What does the Response object in Retrofit contain?

contains the actual HTTP response, including success or error details.

7
New cards

: What is a Request object in Retrofit?

represents the HTTP request sent to the server.

8
New cards

How do you add Retrofit dependencies in an Android project?

Add dependencies for Retrofit, Gson (for JSON serialization), and Coroutine support in the build.gradle file.

9
New cards

How do you define a data model for Retrofit in Kotlin?

data class Post(

val id: Int,

val title: String,

val body: String

)

10
New cards

How do you define API endpoints in Retrofit?

interface ApiService {

@GET("posts")

suspend fun getPosts(): List<Post>

}

11
New cards

Why use a ViewModel for network calls in Jetpack Compose?

It keeps the UI layer clean, lifecycle-safe, and allows network requests to persist across configuration changes.

12
New cards

What is MockWebServer used for?

It simulates network requests and responses, allowing unit testing of Retrofit API calls.

13
New cards

Why is error handling important in Retrofit?

ensures a smooth user experience by managing network failures, parsing errors, and other issues.

14
New cards

What state management options are available for Retrofit data?

StateFlow and LiveData are commonly used to observe data changes and trigger UI updates.

15
New cards

Why should network requests be handled in the ViewModel?

Performing network requests in the ViewModel ensures data survives configuration changes and keeps the UI layer clean.

16
New cards

How does Kotlin coroutines help with Retrofit?

allow you to perform network requests asynchronously using suspend functions, preventing UI thread blocking.