Home > Android, Mobile > Deadlocked


December 27th, 2011

I recently started spending more time on my Android Clock Widget Project. I’ve implemented some much needed caching of the SVG definitions, speeding performance of clock rendering substantially. In addition, I’ve been working on building a nice graphical clock selector. Unfortunately, this selector is causing me lots of frustration due to a race condition that keeps deadlocking the application’s UI thread.

Parsing and rendering the various SVG layers that make up each clock is a relatively expensive operation. Locking up the user interface while doing these operations is bad design and leads the user to believe that the application may not working correctly. What I’m attempting to do seems pretty simple on the surface. The following screen capture shows the (partially working) goal:

Clock Skin Selector

The selector consists of two columns, an image of the clock on the left and the name of the clock on the right. Using the standard ListActivity support, the goal is to show an indeterminate progress image in the left column until the layers have been loaded and rendered. At that point, the animated progress image is hidden and the clock image is displayed.

The implementation is simple in concept. The list adapter subclasses the standard BaseAdapter implementation to provide an implementation of the getView method. The getView method delegates loading of the clock’s image to an asynchronous task, keeping the user interface alive. When the asynchronous task completes, it signals the adapter by calling notifyDataSetChanged. The next call to getView will hide the progress animation and display the rendered image.

While this is mostly working, I’m hitting a random deadlock condition that locks up the UI thread, usually resulting in an “Application Not Responding” (ANR) error message to the user. All of my attempts to diagnose and resolve this issue have ended with nothing but frustration. So far, I’ve tried all of the “standard” approaches to diagnose this:

  • Analyzed the traces.txt file generated by the ANR.
    Unfortunately, the process never shows up in the log file.
  • Force-generated a traces.txt file using kill SIGQUIT pid while the application was still running.
    Again, the process doesn’t seem to show up. Instead, I see “W/dalvikvm(19144): threadid=4: spin on suspend #1 threadid=9 (pcf=0)” whenever attempting this.
  • Attempted to use the standard Eclipse debugger to suspend the UI thread once it is locked up.
    No big surprise that it did not work.
  • Added lots of Log output trying to pinpoint the hang.
    At least from that logging, it doesn’t appear to be a hang anywhere directly in my code.
  • I even tried to use method tracing to see if I could figure anything out.

At this point, I’ve run out of good ideas on how to track down and fix this problem on my own. I’ve gone ahead and joined the Google android-developers group and asked for ideas on solving this. I’m still waiting for my question to clear moderation to see if anyone else can offer any insights. If anyone reading this has any ideas, I’d love to hear them. Until then, this project is officially deadlocked.

Categories: Android, Mobile Tags:
Comments are closed.