From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Retrieve remote data with Retrofit

Retrieve remote data with Retrofit

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Retrieve remote data with Retrofit

- [Instructor] I've added all the permissions and dependencies to work with retrofit and co-routines and I've defined a service interface. Now I'm ready to make a web service call. I'll go back to my repository class. In the branch for this video, I cleaned up this class a lot. I've removed all the code referring to local files because now I want to get my primary data from that web service. I'm going to rename this function from getMonsterData to callwebservice and then I'm going to add an annotation above it, WorkerThreat. That's an indicator that this function will be called in a background threat. I'll be using co-routines to do that, but we'll get to that at the end. I'll also add the suspend keyword before the function definition. Within the function, I'll check my network status with an if condition. I'll say if network available. And if it is, I'll do all the work I need to create a retrofit object and call the service. I'll create a variable that I'll call retrofit. I'll get…

Contents