Archive for April, 2009

Google I/O 2008 – Dalvik Virtual Machine Internals

I’m gonna try this link again…

Awesome Book Title

Great acronym: WTF!

Posted via web from Eric Burke

Not a Memory Leak

Yesterday, I posted this picture from the Snake game on my G1 phone:

I received this comment from Alex:

Snake with open/close is a memory leak . As a weather has nothing to do with Android just bad app.

Duplicating the Bug

Here is how I duplicate the bug:

  1. Start playing a game
  2. Change the phone orientation, i.e. open or close the keyboard drawer
  3. Push the trackball up to resume the game

Just repeat steps 2-3 a few times until it crashes, it usually takes a few tries. Is this a memory leak, as Alex suggests?

Diagnosing the Bug

  1. First, install the free Android SDK. Google provides excellent instructions, so I won’t explain it here.
  2. Configure your G1 phone for USB debugging. From the home screen, go to Menu -> Settings -> Applications -> Development, and select USB debugging.
  3. Now connect your G1 phone to your computer via the USB cable.
  4. Run ddms to start the Dalvik Debug Monitor. You’ll find ddms in the tools directory where you installed the Android SDK.
  5. Make Snake crash and find the stack trace in the Log.

As you can see, this is an ArrayIndexOutOfBoundsException, not a memory leak. Here is the complete stack trace:

java.lang.ArrayIndexOutOfBoundsException
    at com.example.android.snake.TileView.setTile(TileView.java:150)
    at com.example.android.snake.SnakeView.updateApples(SnakeView.java:434)
    at com.example.android.snake.SnakeView.update(SnakeView.java:405)
    at com.example.android.snake.SnakeView.setMode(SnakeView.java:336)
    at com.example.android.snake.SnakeView.onKeyDown(SnakeView.java:279)
    at android.view.KeyEvent.dispatch(KeyEvent.java:718)
    at android.view.View.dispatchKeyEvent(View.java:3154)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:734)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:734)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:734)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1589)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1084)
    at android.app.Activity.dispatchKeyEvent(Activity.java:1856)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1560)
    at android.view.ViewRoot.deliverKeyEvent(ViewRoot.java:1616)
    at android.view.ViewRoot.deliverTrackballEvent(ViewRoot.java:1508)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1201)
    at android.os.Handler.dispatchMessage(Handler.java:88)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3739)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
    at dalvik.system.NativeStart.main(Native Method)

Avoiding Bugs Like This

I find that most Android bugs occur when Activities pause and resume. Changing screen orientation is a great way to crash many applications. That’s because orientation changes trigger lifecycle events. These events will occur at inopportune moments, such as when you receive phone calls or the user hits the Home button.

Applications that do not properly react to onPause(), onResume(), and other such methods will eventually fail.

You can use the UI/Application Exerciser Monkey to stress test your application. In the emulator, you can simulate incoming phone calls, which will pause the current Activity. You should also open and close the keyboard — repeatedly — while your application is performing tasks.

In summary, you need to brutalize your applications. Try really, really hard to break them. Android is a challenging environment because you must carefully manage threads, react to a complex series of lifecycle events, and deal with limited resources.

Android Hall of Shame

A few minutes ago I tried to take a picture with my G1 phone. My phone failed:

So I grabbed my Canon PowerShot SD1100 camera and snapped the picture shown above. My Canon camera never shows a “Force Close” error. It just works. I expect the same user experience from my phone. Is that an unreasonable expectation?

Here is the Weather Channel Android application, one of the most popular apps in the Android Market. It Force Closes becomes unresponsive from time to time. To get this picture, I simply tapped the tabs quickly:

Next I opened the Snake game. I opened and closed the phone a few times and…well, you know what’s coming next:

This is not good enough.

Who do I Follow on Twitter?

I generally don’t pay attention to who follows me on Twitter. In fact, I have GMail automatically archive Twitter email notifications whenever someone new follows me. That bucket currently has 700+ unread messages. (I just checked so I could put a number in that sentence.)

This offends some people. They believe that by following you, you should in turn follow them back. You scratch my back, I’ll scratch yours. Twitter is weird like that.

So how do I decide who to follow? I generally follow these groups of people:

  • People I work with or know personally.
  • People who are well known in fields I’m interested in, like Android development.
  • Familiar names that keep popping up on Twitter among the people I already follow.
  • People who @reply to me with interesting comments.

More and more, that last bullet is how I choose who to follow. If someone sparks my interest with a comment, I’ll click their profile and check out their time line and bio. If I like what I see, I’ll follow. It’s as simple as that.

Un-Follow

If people spend a lot of time tweeting about religion, teabagging, or other things I don’t like, I silently un-follow. That stuff stresses me out, which kind of defeats the whole purpose of Twitter. For me, Twitter is a way to relieve stress and amuse myself.

Speaking of un-following, there are tools to notify you when someone un-follows. Last year someone (who I don’t know) send me a personal email telling me he was un-following me. It’s OK, really. You don’t need to tell people when you leave, just go away.

I believe people should not concern themselves with un-follows. Sanitizing your thoughts and censoring yourself is a great way to be boring on Twitter. Instead, just be yourself and have fun.

Enhanced images in GMail

Well, it’s about time. You no longer have to use workarounds to put images into your messages or attach images when you really want to inline them. Just turn on “Inserting images” from the Labs tab under Settings, and you’ll see a new toolbar icon like this:

Nice improvement, though drag and drop is what we really want. :-)

Posted via web from Eric Burke

Hopside Down Beer Mug Glass

I’m going to order one of these today.

Posted via web from Eric Burke

Who Failed English?

I received a poor rating on my State Capitals application from "Raymond". He gives only 3 stars and writes (in the Android Market):

"You may ace your geography test, but you fail English: the correct spelling in this context is 'capitol'."

Actually, I am correct and Raymond is wrong. The capitol is the building in which a state legislature meets. The capital is a town or city that is the official seat of government in a political entity, such as a state or nation.

I used a dictionary and confirmed this before I wrote the app. If only I had his true identity, I could contact him about his mistake. For now, the best I can do is report his comment as spam.

Posted via email from Eric Burke

Victory!

Posted via email from Eric Burke

Grill assembly commencing!

Posted via email from Eric Burke