I worked on creating a beautiful graphic selector for an Android project. Unfortunately, this selector causes me a lot of frustration because of the deadlock in the application UI thread. Analyzing and rendering the various SVG layers composing each clock cycle is a relatively expensive operation. UI blocking during these operations is clearly a bad design, so I try to give good feedback.
The selector consists of two columns, the image of the clock on the left and the name of the clock on the right. Using standard ListActivity support, the goal is to display an undefined progress image in the left column until the time levels are loaded and displayed. At this 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 uploading the clock image to the asynchronous executing service, supporting the user interface. When the asynchronous task completes, it sends the runnable to the user interface thread to hide the progress indicator and show the image. There is logic associated with the correct processing of types of processed items.
While this basically works, Im hit a random deadlock condition that blocks the user interface thread, usually resulting in a "Application Not Responding" (ANR) error message to the user. All my attempts to diagnose and resolve this issue ended only in disappointment. So far, Ive tried all the "standard" approaches to diagnosing this:
- The traces.txt file generated by ANR is analyzed.
Unfortunately, this process never appears in the log file. Created Force file traces.txt using the kill SIGQUIT pid command while the application is still running. Again, the process does not seem to appear. Instead, I see "W / dalvikvm (19144): threadid = 4: spin on suspend # 1 threadid = 9 (pcf = 0)" when I try this. - Kernel-level deadlock prediction included, but it never showed anything
- An attempt to use the standard Eclipse debugger to suspend a user interface thread after it has been blocked. There is not much surprise that this did not work. Added a lot of log output to pinpoint a hang. At least from this magazine, it does not seem to be hanging somewhere directly in my code.
- I even tried using the method trace to see if I could understand anything.
At the moment, I am running out of good ideas on how to track and solve this problem myself. I removed all the synchronization in my code, and I'm still chatting, implying some kind of hang in the base code of the platform. Without a trace of the stack, I really fly blind at this point. Can anyone suggest any ideas?
source share