Successfully Integrating Web Services Into Your Android Apps
November 29, 2012 android

One of the things I’ve noticed budding Android developers struggle most with is how to properly integrate content being pulled form web services into their Android apps. Many of them have been focusing exclusively on figuring out layouts and other user interface related issues and haven’t yet developed an understanding of the underlying threading model in Android, and the fact that you don’t want to do network IO (or anything that takes time for that matter!) on the “main” thread. Some of them have already discovered ASyncTask, but find the documentation a bit difficult to digest or simply lack a nice clean comprehensive working app that demonstrates the concepts. I recently posted a screencast on YouTube (embedded below) that is actually a recording of a portion of a lecture I give in my mobile app develop course here at GVSU. The video seems to be getting a fair amount of views on YouTube for the short time its been available and I’m also getting a number of requests for the source code.

Download the source code on github.

In this video I walk through the implementation of a fictitious app I implemented called TopTracks. The app uses publicly available web services on the Last.FM music social network to display the current most popular music tracks among Last.FM users in various metro areas across the United States. In the course of the code walkthrough we cover how to actually issue the HTTP requests, how to parse the JSON result strings we receive in response, and how to properly code this up in an ASyncTask in a way that moves the time consuming network fetch into a background thread, but still giving us the opportunity to update the view hierarchy with the main thread once the fetch completes. We also take a look at a custom ListView Adapter to demonstrate a typical user interface for displaying an array of data fetched from a network service. The source code covered in the screencast is available here.

If you are in the process of learning to develop for the Android platform, you might be interested in a series of Android screencast tutorials I’ve given in my lectures and made available on YouTube. I’ve embedded the playlist below.

"9" Comments
  1. Pingback: sending excel files to and android app - How-To Video

  2. Hello Mr.Jonathan Engelsma, i modified your code to my requirements.

    The thing is, i’m getting the response code in JSON format in the browser, but i could not get in the android app, resulting…

    “Can not find Result Data. Please Try Again !”

  3. Hari Hara Kumar

    Thank you so much for the tutorial Sir. That was very detailed and helpful.

  4. Thank you very much for this video – I’m a veteran Java programmer but relatively new to Android development (at least on a serious level). I lead the Tulsa Java Developers group and one of our projects is surrounding Java on the Raspberry Pi. I started looking into a good tutorial on JSON REST consumption on Android to allow us to create a decent control/status mechanism for our PI projects. I will be presenting on both topics at Tulsa Techfest 2013 – the Android side is going to borrow heavily from a couple of tutorials including yours and I wanted to thank you for providing it. I’ll also be linking back to your pages in my presentation for further education of my attendees.

  5. @Andrew – glad you found the tutorial useful. Hope your TechFest presentation goes well!

  6. As a student still in High School, these tutorials really give a solid classroom experience. Thanks for the knowledge! 🙂

  7. Hi,

    I can’t get import this project to eclipse ADT.
    Any sugestion ?



  8. Thank you very much Mr.Jonathan ,, can u give me the Code Project Please 🙂 ?

  9. Sir, I got your code form github and trying to change in JSON format for my need.

Leave a Reply