the mobile montage

a collection of scattered thoughts on mobile technology and related topics…

Successfully Integrating Web Services Into Your Android Apps

Posted on | November 29, 2012 | 9 Comments

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.

Comments

9 Responses to “Successfully Integrating Web Services Into Your Android Apps”

  1. sending excel files to and android app - How-To Video
    April 15th, 2013 @ 1:34 am

    […] databases and programming that involves communication on internet. I’ve been looking at this http://www.themobilemontage.com/2012/…, but this uses an existing third party API, and i don’t know enough yet to know if this […]

  2. Pavan Ravikanth
    May 9th, 2013 @ 10:31 pm

    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
    May 27th, 2013 @ 5:31 pm

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

  4. Andrew Chandler
    October 8th, 2013 @ 11:36 am

    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. Jonathan
    October 8th, 2013 @ 12:08 pm

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

  6. Darren King
    December 26th, 2013 @ 11:05 am

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

  7. Silvio
    May 12th, 2014 @ 11:57 am

    Hi,

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

    Thanks,

    Silvio

  8. Ahmad Alkhateb
    October 2nd, 2014 @ 12:35 pm

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

  9. Rashad
    January 4th, 2015 @ 5:08 am

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

Leave a Reply





  • Search

  • About Me

    Jonathan Engelsma

    Jonathan Engelsma is a computer scientist, programmer, teacher, mobile technology enthusiast, inventor, beekeeper and life long learner. He is currently a Professor in GVSU's School of Computing, where he leads the GVSU Mobile Applications and Services Laboratory.

  • Find me on the Social Web