Saturday, June 19, 2010

The dreaded Android ANR (force close)

Application Not Responding is a message I don't really like to see, unless it is early in development. It means you are doing something wrong and if you want to sell your app, you better fix it. The basic fix is to move your slow process/code into a Thread, but that is another topic.

I sell apps and my code has lots of extra error handling for strange cases that come up. In fact, the new Android Market feature that provides you error reports for your apps is handy. After you get a few thousand users of your apps you will see all kinds of odd things happen to your beautiful code. Mostly, you just have to catch some runtime errors you never heard of and handle them gracefully.

Today I will tell you how to get the detailed stack trace explaining exactly what caused the ANR. Every ANR puts a trace file on the phone and that is what you need.

How to get the trace
  1. connect the phone to your computer (you need the Android SDK and USB drivers for this)
  2. open a command window and cd to the android sdk tools directory
  3. run this command: adb pull /data/anr/traces.txt .

traces.txt is now in your tools directory. It is human readable so check it out.


1 comment:

  1. Thanks I just used this so I could forward a trace to Grooveshark :)

    ReplyDelete

Thanks for your feedback!