Bye bye birdie!

Last night i decided to do a digital reset of sorts. Ok, well maybe it was thrust upon me because silly me forgot to do a backup before i flashed a new custom rom on my phone. ALWAYS DO A FULL BACKUP FIRST!!!!

I usually do a backup. But i’d flashed this particular rom on several previous occasions and it had always worked flawlessly. Enter Murphy and his annoying law. This was at about 11pm. You know that sinking feeling you get when something really REALLY bad has happened and you’re not sure you can fix it? Ya, that’s what i felt when i was looking at my blank screen. Welcome to “you’ve been bricked”.

After several hours of frustration (at 2am i finally gave up, resigned to having to get a new phone soon – wasn’t that going to be a fun conversation to have with the wife. $$$). But wait, the story has a happy ending. Bear with me. I crashed, and woke up early (it’s impossible to sleep in with young school aged kids in the house). And within about 30 minutes my phone was humming along nicely. Moral of the story? Well. 1st moral: ALWAYS BACKUP before you do something potentially dangerous. 2nd moral: Never try to solve complicated tech problems at 2am.

Sadly, since i hadn’t backed up recently, the best i could do was restore an older backup from 2 months ago. Which might not seem all that bad. But … 2 months of angry birds 3 star levels lost? Seriously. That’s what i was most worried about. Everything else i could either get back through “the cloud” or my other backups. But my angry birds data was irretrievably lost :(

But as the day went on and i starting bringing things back online one by one, i realized something. Probably 90% of the “stuff” i had on my phone was digital clutter that i didn’t really care about. I hightly doubt i’ll miss it (including the angry birds, angry birds rio, angry birds seasons, angry birds space, and bad piggies games that sucked so much of my time). I’m curious to see what i do end up putting back on. Liberation!

Mobile coding lessons i’ve learned from writing an Android application

I recently completed a major version of an Android client for work.  I guess no program is every really “complete”.  But, it’s at a good stopping point for the moment so i thought i would jot down some of the lessons i learned.  These can really apply to any type of development, not just mobile Android.

  • The network layer is unreliable
First of all, cell phones have flaky connections that come and go.  They might be on wi-fi, they might be on a cell connection. They might be in a tunnel.  Maybe they’re in airplane mode.  Doesn’t matter.  You can’t count on a network always being there, and even when it is there, you have to assume that it will be flaky and return strange errors.  It’s important to have a robust network layer that has retries built into it for various errors such as timeouts, unavailable, etc.  Don’t just assume the backend is down.  Assume first that their connection is temporarily out of sorts, retry a few times, and THEN give up.  That will eliminate 90% of the network errors a user has to be aware of.  Oh, and some phones, vendors, flavors of Android all have weird little network quirks that only they exhibit.  Yet another reason for a robust network abstraction.
  • Deal with threading issues

If you don’t want to die from a thousand little cuts, design your code to be thread-safe from the beginning.  Many phones now have multiple cores and really do execute things in parallel.  Add to that fact that any complex app will likely have multiple IO requests in flight at the same time (whether from the file system, database, or network) that can return asynchronously, and you are ripe for threading problems.  Deadlock, data switching out from underneath you, etc.  Use the threading tools. Synchronize, lock, atomic operations and especially the concurrent package are your friend.

  • Be asynchronous

Seriously.  Don’t block the UI thread for any reason.  If you’re loading a file from the file system, accessing the database, making a network call, or even doing some heavy number crunching, do it on a thread and call back to the UI when you’re done.  Android has some nice abstractions to help with this, including AsyncTask, and Handler classes.  You can also do traditional Runnable’s if you like.  But whatever method you use, make sure you have an async layer built into your app that’s easy to use.  Make sure your main application logic can deal with everything being asynchronous.  Your users will thank you for a snappy app.  Corollary: Don’t block the UI needlessly with modal dialogs unless you absolutely have to wait for a result.  Let the user do other things while your background processes are running.

  • Be aware of constrained resources

Ya this is a fun one.  You have very limited memory in which your application can run.  We’re not on a desktop here.  Some phones are far worse than others as far as how much memory they let you have.  Loading images is especially dangerous for running out of memory.  Have a strategy in place to only keep in memory what you need.  Don’t keep things lying around longer than you must.  Memory is fast, but disk is cheap and certainly faster than the network and definitely better to take a few milliseconds to reload an image from the drive all the time rather than running out of memory and crashing the program.  So load it from the network, save it to disk, cash in memory until you run out, then just have some type of LRU cache.

  • Understand and work with the application lifecycle

This one may be somewhat android specific, but the general idea is sound for anything:  Each activity (screen/window) has a lifecycle.  It’s created, setup, running, paused, and eventually destroyed.  It might also be resumed and restored in the middle of all that.  The framework provides rules about when all these things happen and how you should deal with them.  Make sure you do the correct thing at the correct time.  Expect that since this is a mobile environment with lots of stuff going on that your activity might be asked to pause or shutdown at any time, even mid-process.  Save off your state, be able to restore it, and know how to deal with data inconsistencies that might result.  Don’t expect that x then y then z will always happen.  X and Y might happen, and you’ve started Z, but then a phone call comes in and your activity goes away.  When you come back, what do you do?  Make sure you do the right thing.

Don’t diss the Android, dude …

Someone sent me a link at work saying how poor Android is.  I had to respond.

Update: Silly me, forgot to include the original link.

This is my email:

> Android OS (whilst hidden behind the beauty that is HTC Sense) is an inherently geeky, inconsistent, temperamental and beta-like OS.

  • geeky: yes (and in my opinion, that’s a good thing. not everyone is an apple fanboy) :)
  • temperamentaland beta-like: to some degree, yes.  give it time to mature a bit more.  every iteration it improves drastically.  Google isn’t sitting still

> It responds inconsistently to what should be basic functions of a phone

  • Agreed.  That is sometimes annoying.  Slow to load the phone dialer.  Easily fixed via software update.

> Exchange sync having random hiccups.

  • Never noticed any problems with this.  I use the exchange sync for work email and have always had my email there when i wanted it.

> The limitation of the OS not allowing you to install applications onto the microSD card

  • 100% agree with this one.  It’s SUPER annoying and aggravating.  It limits how many apps i can have, how large and complex apps can be.  Google has said they’re working on this and with a future software update this will no longer be an issue.

> Auto memory management is poor at best.

  • Not sure i agree with this.  There is an excellent article here by a Google engineer involved in this that details how and why they did things the way they did. .  That being said, there are a few poorly designed apps that don’t play nice with Google’s best practices for memory management.  My response: Don’t use those apps.  They will get low market ratings and bad comments so you can easily avoid them.  And there are always a dozen alternatives that don’t have the problem.

> Android is not and can not be an “iPhone Killer”, nor really even a competitor.

  • I’m always annoyed when someone says “Android is an iPhone killer.  It’s not.  But i do think it’s a valid competitor.  Especially with the newer versions of the OS and the newer hardware (Droid Incredible, Nexus One, EVO 4g).  It’s numbers are growing like crazy.  In fact, last quarter, Android outsold iPhone.  (Both of which are behind RIM, which itself is waaaay behind Nokia).

> The Android market is disjointed, confused and inconsistent, whilst Apple have created a stable, consistent platform that whilst limiting in some ways, allows users a level of comfort that Android does not.

  • Apple-fan boy speak there.  I 100% disagree with this statement.  It’s precisely Apple’s “stable, consistent platform … limiting in some ways” that has made me have absolutely no interest in doing personal development for iPhone OS.  I don’t want someone telling me what i can and can’t put on the market.  “Oh, we don’t like your app, sorry”.  and people with big public forums or insider clout at apple get their apps through anyway, where the little guy wouldn’t.
  • And it’s exactly the disjointed, confused, and inconsistent Android market that excites me.  It’s challenging.  Yes – you have different screen resolutions and OS versions.  All of which are documented in detail and EASY to code for and test in the emulators.  It adds maybe an hour of time to do a little testing for different screen sizes.  So what?  And hey – i can publish anything, anytime.  If it’s crap or malware, the market will rate it poorly and nobody will download it.

> Ask older Android handset owners if they enjoy being stuck on Android 1.5

  • He has a point here.  My response: Get a new phone. How long do people keep their phones on average nowadays?  usually the 1-2 year contract from their carriers.

> you can now walk into almost any store anywhere in the world and buy an accessory for an iPhone.

  • That is a also a good point.  But i have no trouble finding accessories on Amazon.  I rarely walk into a store to buy any tech accessories anymore…  Plus it’s cheaper.  You can get a standard micro-usb cable for $5.  You don’t have to pay $30 for a special iphone cable :)

> Too many form factors. Too much variance in OS versions. Too many product releases, too quickly.

  • I think that’s a good thing.  Choice.  You don’t like phone x?  Try phone y.  You want something fixed?  You won’t have to wait long for it, because the releases happen quickly.  Release early, release often.

Both sides of the argument have merit, and i think that both OS’s have a place.  iPhone rocks, no doubt about it.  But don’t discount android as over and done with.  It’s not going anywhere but up.  The more choices consumers have, the better.

Chuck Norris vs the slump

I’m in a weird slump at work. I enjoy my job, generally. But i’ve really missed coding of late. I rarely have time at work to do anything coding-wise. And usually when i do get some time, it’s a half hour here, an hour there. Not enough to really get into anything. So i write emails, update documentation, go to meetings, wander around and make sure nobody is blocked on something, etc.. Typical managerial life i suppose?

Lately, however, i’ve really been getting the bug to code. It’s what i enjoy most. My only solution is to spend time on the weekends or late at night after everyone is in bed. The problem is … code what? I don’t have any ongoing projects at the moment. My website is stable and does what i want. I’m sick of rehashing my inventory program over and over (although i probably will create a mobile version eventually). So i’m sitting there on Saturday trying to come up with something to do when i decide to play around with the twitter api’s.

They’re really simple – just fetch a url with a couple of parameters and parse the results. Easy peasy. So i decide to start playing around with writing a twitter application that will fetch all of a persons tweets, retweets, mentions, and replies and store them in a local database. It will be smart enough to be able to run incrementally after that to only retrieve new stuff since the last update. Stick it on a cron job, let it run, and the database fills up.

Not sure what i want to do with the data once i have it, but hey – that’s a problem for another day. I could create a webservice to fetch it and display on a webpage. I could integrate it into my blog. I could write a mobile app to view it. Maybe link to something on facebook. Whatever. The important part is to just make sure i have the data now before it’s inaccessible (twitter only lets you go back so far via their api calls).

Great – i did that. But it didn’t satisfy me. I wanted to do more. Enter Chuck Norris. He’s the man. You know all those awesome Chuck Norris “facts” floating around? No … well, go look up “chuck norris facts” on google. Or better yet, do a twitter search for “chucknorris”. Suddenly i’m hit with a great idea.

I want to write a widget for android. A widget is a small app that runs on your homescreen that does some specific function. My widget will be a picture of Chuck Norris’ face. When you click it, it will do a twitter search for “chucknorris”, grab a random quote and display it to the user. How awesome is that? And since i’d already done all the hard work of figuring out how to deal with twitter, that only left learning how to write a widget. Turns out it’s not that hard. I had one up and running in 3 hours.

Next dilemma – free or for-pay on the market? i’ve got a free app already. It’s got around 9,000 downloads currently. People generally seem to like it. Would they pay for a Chuck Norris fact widget? Maybe i’ll make version 1.0 free, and i’ll create a for-pay 2.0 version that adds something, like the ability to share a quote. Hmm … ya – that could work.

Why I enjoy my phone so much

I just love my phone. It’s awesome. But why doesn’t it get old after a while? You know – just become something that i use when i need it, and aside from that, it just sits there in my pocket?

I think there are several reasons for this. First is the fact that’s it’s just so useful. I mean, it does so much more than calls. It shows me weather and news, which are constantly updated. I can check movies, sports scores (like i ever do that), order tickets, find a place to eat, play a quick game, read a book, update my facebook status. So reason #1 – it’s a window into the digital world and i’m constantly using it. Thus it never gets old.

But i think, at least personally for me, the number one reason i love my phone is because i can write programs for it. I can have it do whatever i can magine. It’s my “little computer” (as Alex used to so fondly call these things when he was younger). There’s always some new frontier to be conquered. Some new thing to try and make it do. It never gets old, because i’ve never exhausted all the possibilities.

(i wish there were a) Palm emulator for Android and iPhone

As i was sitting there using my Android phone this morning, and my wife was using her iPhone next to me, i thought of all the great apps that exist for these devices.  There are literally over 100,000 apps for the iPhone, and over 20,000 for Android.  Of course, probably 80-90% of those are “crapware”, but hey … that still leaves a lot of great apps.

Even so.  Think of Palm.  Sure, today they’re pretty much a has-been, but Palm was the king of the hill for a LONG time.  And during the height of the Treo years, there were tens of thousands of excellent apps written for the Palm.  I even have a few that i still run via the desktop emulator now and then.

So let’s combine some thoughts here.  I have an NES emulator for my Android phone.  It allows me to play literally hundreds of old-school games.  It’s amazing, and works perfectly.  Why not create a Palm emulator for Android and iPhone?  Think of all the great apps everyone would suddenly be able to run!

As a completely unrelated side-note: Why won’t the makers of Pocket God create an Android version?  Or even a WiiWare version?  I’d buy either (probably both)…

Tech Support

I haven’t done a lot of blogging lately. … Well, that’s not entirely true. I’ve been doing plenty of micro-blogging (facebook and twitter). In the meantime, all sorts of interesting things have happened.

  • The first rocky exoplanet has been discovered. It circles closer to its parent star than Mercury (meaning it’s more like a hellish prison planet than a gardeon of eden), but has roughly the same density as the Earth. Good signs for better discoveries in the future.
  • Google has been doing a number of “unexplained phenomenon doodles“, leading many people to believe that we’ve made first contact with Aliens (because, hey – of course Google would know first, right?)
  • Apple just released something blah blah ipod whoever cares…
  • I just released a new version of Shisensho and actually got a really nice comment from someone! score.
  • My son, Alex just turned 13! Holy crap, i’m the parent of a teenager now. For his birthday, we built him a greenhouse.

But the best thing was this xkcd comic i ran across a while back:

Why the market hesitation?


 It’s funny how i’ll blow between $6-10 a day on some crappy lunch (and usually chuck about half of it away) without even thinking about it. And yet when there’s a cool application on the Android market for $1.50 it gives me pause. Why is that? I do eventually purchase the app if it’s really cool, but as i sat here pondering this i couldn’t come up with a good reason of why i’d hesitate spending $1.50. Even if i don’t like the app, so what? It’s not like i just wasted a huge amount of money…


I’ve just discovered the joys of Qik – live streaming video from my phone!

You can also subscribe to an RSS feed (which allows you to download the videos locally if you like):

I can add a title, set location information (if i want), mark the video private/public, and then it will send notifications (if i want) to twitter, facebook, and youtube whenever i stream live video. How cool is that?

My Android G1 with its 3.1megapixel camera actually does pretty good (especially in sunlight). This will be great for capturing impromptu moments to share with friends and family.

(It might also come in handy if i’m ever in the middle east during a revolution!)

Google IO videos

Well, even though i wasn’t able to attend the Google IO conference this year (turns out i could have if i’d found out about it earlier … oh well; next year!), the folks at theconference were nice enough to record many of the sessions and put them online! I’m going through all of the Android presentations now.

Google IO videos