How to do Asynchronous http


helloandroidWhen I developed my Android freeware against the release SDK, one of the first things I had to work out how to do was how to implement asynchronous http requests in a thread using a Runnable HttpURLConnection. That is, not block the UI while performing a http request thus allowing other things to happen or the user to cancel the request.

Almost all the examples I found were either synchronous or didn’t work with the release SDK. I nearly gave up and started to create my own. Then I came across Ed Burnette’s source code from his book  ‘Hello, Android: Introducing Google’s Mobile Development Platform’. The ‘translate’ source gives a workable example of async http.

Now that the Android OS source code has shipped another asynchronous http example can be found in the IM source.

By the way, also check out Ed Burnette’s excellent PlanetAndroid if you haven’t done so already.

Comments are closed.