My app has a layout that contains some ImageButtons.  In addition, my app 
renders some Bitmaps    for later use.  The Bitmaps are rendered by 
creating a Canvas with a Bitmap parameter, and then drawing into the 
canvas.  This Bitmap rendering task occurs in a non-ui thread, so the gui 
can remain responsive while the bitmaps render.

ANRs occurring.  The caused appears to be that the ImageButton.draw() 
method does not complete.  Additionally, it appears that the method fails 
to complete because the Bitmap rendering task begins rendering while the 
ImageButton is drawing.  

Below are some code snippets, by log output, and the traces.txt file from 
the ANR.  

Is my conclusion possible/likely, that drawing to a Canvas in a non-ui 
thread could cause ImageButton.draw() to hang?  If so, any suggestions to 
fix this?


    private class BitmapRenderTask implements Runnable
    {
    ... 
    public void run()
    {
    Log.e("start render task", rect.toString());
    ...
    Canvas canvas = new Canvas(bitmap);
    Log.e("created canvas", "created canvas");
    //do stuff to draw into canvas
    Log.e("drew to canvas", "drew to canvas");
    ...
    Log.e("done, exit", rect.toString());
    
    public class MyImageButton extends ImageButton
    { 
    public void draw(Canvas canvas)
    {
    Log.e("start drawing", this.toString());
    synchronized (LOCK) 
    {
    super.draw(canvas);
    }
    Log.e("end drawing", this.toString());
    }
    }
    
    My log:
    
    04-24 14:10:12.115: E/start render task(9446): 1 Rect(512, 0 - 800, 512)
    04-24 14:10:12.230: E/start drawing(9446): MyButton1
    04-24 14:10:12.230: E/end drawing(9446): MyButton1
    04-24 14:10:12.230: E/start drawing(9446): MyButton2
    04-24 14:10:12.230: E/end drawing(9446): MyButton2
    04-24 14:10:12.230: E/start drawing(9446): MyButton3
    04-24 14:10:12.230: E/end drawing(9446): MyButton3
    04-24 14:10:12.230: E/start drawing(9446): MyButton4
    04-24 14:10:12.235: E/end drawing(9446): MyButton4
    04-24 14:10:12.235: E/start drawing(9446): MyButton5
    04-24 14:10:12.235: E/end drawing(9446): MyButton5
    04-24 14:10:12.235: E/start drawing(9446): MyButton6
    04-24 14:10:12.390: E/drew to canvas(9446): drew to canvas
    04-24 14:10:12.395: E/done, exit(9446): Rect(512, 0 - 800, 512)
    04-24 14:10:12.395: E/start render task(9446): Rect(0, 1024 - 512, 1084)
    04-24 14:10:12.410: E/drew to canvas(9446): drew to canvas
    04-24 14:10:12.395: E/done, exit(9446): Rect(0, 1024 - 512, 1084)

traces.txt:

http://pastebin.com/s98nEyYt

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to