From the course: Android Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Make asynchronous calls with Retrofit

Make asynchronous calls with Retrofit - Android Tutorial

From the course: Android Development Tips

Make asynchronous calls with Retrofit

- [Instructor] In last week's tip, I described how to use the open source library Retrofit to make web service calls. In recent versions of Android, you have to make these calls asynchronously. I solved that challenge last week by creating an AsyncTask that receives the request, executes the web service call in the background and then handles the response in the onPostExecute method, which is executed in the main thread. But Retrofit actually has tools you can use to make the calls asynchronously without an AsyncTask, an IntentService or any other sort of separate structure. Let's start with the web service. The web service call doesn't change at all. You still create a Retrofit object that's accessible from outside the class and then you define your call using a get or a post annotation. In this example, I'm using a get request to retrieve all data items from the JSON feed. In my current code, I've wrapped the request inside the web service task, AsyncTask class. When I call the…

Contents