Bug Tracker Blog by Corey Trager

A Hacker News app for Android

by Corey Trager 3. February 2010 14:00

BugTracker.NET has been my steady hobby project for 7 years, but the marriage is getting a little dull. From time to time I've flirted with other technologies; I had a week-long fling with Django and a one-night-stand with Flex.

Ok, I know the metaphor is getting annoying. I'll stop.

Anyway, I've started playing with Android development, and I've actually got something to show for it: a "Hacker News Reader" app. If, like me, you are a frequent visitor to Hacker News, and if you have a Droid or Nexus One, then you might find my app handy. It re-formats the headlines and the comments for easier reading on your phone. I've tested it on the 1.6 and 2.0 SDK emulators and on an actual Nexus One (I bought one, but without the T-Mobile service - just the device, as a dev toy) running the 2.1 API's, and it seems to work fine.  The app is in the Android Market; just search for "Hacker News". It's free. 

It looks like this:

The idea of the app is simple - it screen-scrapes the news.ycombinator.com website and displays the text in Android widgets. Because I didn't want  the phone app to be brittle, to be vulnerable to changes in the HTML at news.ycombinator.com that would break the scraping logic, the phone app itself doesn't do the scraping. Instead, the scraping is done by a remote web-based app, hosted at Heroku.com, that servers as a go-between, a proxy. The phone app sends a request to the proxy, which in turn fetches the web page from news.ycombinator.com, and reformats it as XML to send back to the phone app. The proxy gives me a central place to fix breakages, so that all the phone app users won't have to download a new  version when ycombinator changes their HTML. The proxy also does a little bit of caching, to speed things up and lighten its load.

The proxy app could have been written in any web technology, but I happen to have written in Ruby, using Sinatra, a very lightweight web framework, and it's deployed on Heroku.com, using their clever git-push deployment scheme. The combo of Ruby/Sinatra/git/Heroku seems really well suited for this type of small scale web development, easy to learn, and kinda fun.

I really think you'll find the phone app to be truly useful. But there's nothing special about the technology of it. It just fetches the XML from Heroku and displays it.

I'm still a beginner at the Android SDK, but I'm starting to pick up speed. There's nothing in particular hard about learning, but like with learning any new technology, the smallest things can sometimes go slow, and with Android development, I'm learning several things at once:

1) Eclipse - It's kind of amazingly big. I get lost in it. Like, the first time I tried to debug and the "perspective" switched to debug, I didn't know what happened and I didn't know how to get back to the original window arrangement. If I'm having problems with Eclipse, mostly I blame myself, but there are some annoying things where I blame Eclipse (or is it the Android Developer Toolkit plugin?). Like, if I have focus on an XML file instead of a java file and then select "Run", the Eclipse tries to run something else - I don't know what - but not my app.  On the plus side, the "Intellisense" works really well.

2) Java - I've done professional work with Java in the past but, it's been about a decade. I forgot how verbose it can be. I have code in the ruby app that fetches the URL from ycombinator and code in java that fetches the URL from heroku. Guess which requires more lines of code, the ruby or the java?   I don't struggle with the java language, which is pretty much like C#, but with the library, finding my way around. But, that's going to be true with any new language, Python and Ruby too.  Picking up speed comes from knowing the libraries well.  Even if you know the standard Java libraries, you'll still have to learn the new libraries in the "android" namespace.

3) The Android SDK itself. The most frustrating part for me has been the XML layouts, because when you get the XML to be well-formed, your app can still crash right away with layout issues, and I don't know how to debug those, except by re-reading my XML and comparing it to something that works - or used to work.  Also, I haven't figured out how to diagnose runtime exceptions well at all, so I code just a very little bit at a time before doing a test, so that if something does go wrong I only need to search for the problem in a few lines of code I've changed since the previous test.  Yesterday I omitted a call to the super class in onResume() and that took me about an hour to figure out.  I went straight from the SDK's Notepad tutorial to developing my app, but I'd advise others to spend more time with the SDK samples. I'm circling back to them and trying to solidify my learning.

If you try the Hacker News app, please let me know how it goes.



2/3/2010 3:50:23 PM #

Great idea! Incidentally I'm also currently writing my first Android app (which is a scraper, too) and I feel your layout pain.

I am a full-time Java dev so I know it well and the library issue isn't so bad for me, but I have  switched to Netbeans for development. On my Macbook I found it way more usable than Eclipse and it has an Android plugin, too.

(I wrote a little summary of me switching to Netbeans, in case you're interested: lenni.info/.../)

Lenni |

2/3/2010 3:51:18 PM #

The URL got messed up: lenni.info/.../

Lenni |

2/3/2010 5:44:13 PM #

Sounds like a great idea! I went to search for it with my Samsung Moment (which only runs Android 1.5, much to my chagrin), and it doesn't show up. This often happens when an app is developed for 1.6 or 2.0. Any possibility that you could release it for Android 1.5 too?

Colin |

2/3/2010 6:28:04 PM #

I second this request, I'm running 1st generation Android as well...

Tobias Cassell |

2/4/2010 3:46:03 AM #

Well, I downloaded the 1.1, 1.5. and 1.6 SDKs.   It wouldn't compile for 1.1 and 1.5.  It worked ok for 1.6, so I re-released, with minSdkVersion set to 4.   The compiler complained about the "res" folder.  If folks want to point me to resources so I can learn more about versioning practices, and how that's supposed to work with the Market, I'm listening.

Corey Trager |

2/3/2010 9:02:52 PM #

Same here - doesn't show up on my Hero.

Btw, this may alleviate some of your XML troubles: [Android] Auto Formatting Android XML Files With Eclipse beerpla.net/.../

Artem Russakovskii |

Comments are closed

Powered by BlogEngine.NET


Comment RSS