My current list of Android mistakes

As is traditional, I have made silly mistakes while starting a new project – this time, developing an Android app. Here are the biggest ones:

  1. Thinking it wouldn’t be that hard…

    When I finally got USB debugging to work, everything else seemed so easy in comparison. Sure, I’d never programmed for Android before, but it’s well documented… I don’t need to read all of those long, boring-looking guides! I’ll just jump into coding!

  2. … and then running before I could walk

    For my first application, I decided to do something that would mean creating my own custom views and widgets, before I’d even figured-out how the built-in ones worked.

  3. Coding while unwell

    All this, while I had a horrible cold that meant I couldn’t think clearly, and having slept poorly. This is not the best state of mind for debugging things you don’t understand.

Note that none of these are actually specific to Android… I just need to be more patient and read the manual, really!

Not helping this of course, was that the error complained about an invalid cast that didn’t appear in my code, and highlighting a line in the Choreographer class, simply indicating that it happened in a callback. I eventually figured it out:

If you get a complaint about casting between a LayoutParams class and a MarginLayoutParams class, it may well be that you’re using measureChildWithMargins() instead of measureChild().

As another point, when setting colours in hexadecimal, Android uses ARGB. So, while label.setTextColor(0xff0000) will compile fine, you’re giving it an alpha of 0 – fully transparent. To be opaque, it needs to be label.setTextColor(0xffff0000), or something along those lines.


I might reveal what the app will be soon, now that I’m actually making a bit of progress. I’m sort-of hoping to get it on the Android market before the end of October, along the lines of the Ludum Dare October Challenge… though it’s not a game, and I’m not sure if I’ll charge for it. No, I think I will charge. I’ll just have to make sure it works solidly.