Monthly Archives: November 2013

<3s Threadless for Android Launch!


For the past few weeks I’ve been learning Android development in order to diversify my skill set a bit. Plus I needed to justify buying a Nexus 7 tablet somehow. I decided to learn a bit using the Big Nerd Ranch book, and once I went through enough examples I was confident enough to attempt recreating my Threadless app for Android.

I was planning on reaching feature parity with the iOS app before releasing it, but I decided that a more frequent update cadence is probably better when it’s possible. The Google Play store makes it really easy to alpha and beta test, as well as promote beta builds to production. Rather than taking a week to find out that your app does not meet the requirements of Apple, you can simply push out a build and it’ll be ready in a few hours. This is probably one of the best “features” of being an Android developer.

While Android has its fair share of “WTF” features, I actually kind of like it. I think it’s quickly getting to the point where Android’s advantages (amazing integration with very high quality Google products) will outweigh Apple’s (Super awesome third party applications albeit running in a tightly confined sandbox).

Design Patterns: iOS and Android – Dispatch Queues and AsyncTask

For the past few weeks, I’ve been learning Android and porting one of my iOS apps to the platform. While there are many differences between the two platforms, it’s also kind of interesting to see common design patterns between them. I figured I should write up the common design patterns that I notice and maybe help out some iOS developers who are also learning Android like me.

Today I’ll look at doing asynchronous tasks in each platform. While there are many ways of doing this in both platforms, I’ll take a look at Dispatch Queues for iOS and AsyncTask in Android, since that’s what I’ve been using lately.

In iOS, you can use the dispatch_async call to run code on a background dispatch queue. Say we get an NSArray of JSON objects and want to save them to a Core Data store. We can call dispatch_async on a dispatch queue, process all of the objects and then update the UI by using dispatch_async again on the main queue:

In Android, performing a lightweight asynchronous task requires you to subclass AsyncTask. I guess I’m using the term “lightweight” loosely because creating a subclass just to do something asynchronously seems a bit heavy, but at least you get to reuse your code!

You must define three generic types which describe what the input is (in this example, a String), the progress type (an Integer) and a result (a Boolean).

Once you have that AsyncTask set up, you can call

to run your asynchronous task. One tricky thing to remember is that execute takes a list of objects and sends it to doInBackground as an array. I’m not BFF with Java so the syntax threw me a bit, but apparently it’s using a feature called varargs that’s been in Java for a while now.

That’s all for today. I hope this blog post was useful. I certainly found it useful, since I had to do some research to really understand what the heck I was writing about. I’ll probably write about UITableViewDelegate/Datasource vs. ListAdapter next, unless there’s something else that seems more timely.