Android Networking: Beyond the Basics

Sep 8 2022 · Kotlin 1.7.10, Android 12, Android Studio Chipmunk

Part 2: Retrofit With Kotlin Coroutines

10. Include Built-in Retrofit Support for Coroutines

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 09. Use Kotlin Coroutines to Shorten API Calls Next episode: 11. Challenge: Coroutines

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Retrofit has built-in support for couroutines. Lets see how you can use this support to simplify your code further.

Demo

This demo will be super short, but also very sweet in that manner! :] Open RemoteApiService.kt. Change the deleteNote API call to the following:

suspend fun deleteNote(@Query("id") noteId: String): DeleteNoteResponse
suspend fun deleteTask(taskId: String) = try {
  val data = apiService.deleteNote(taskId)

  Success(data.message)
} catch (error: Throwable) {
  Failure(error)
}

Lecture 2

This is why coroutines are so awesome! :] They are super easy to use, easy to understand, for at least the fundamental concepts, and they take care of a lot of things, like threading, instead of you. In the next episode, you’ll refactor the rest of the API calls, to rely on coroutines! :] See you there!