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.


Powered by BlogEngine.NET


Comment RSS