2

I have a function

@Override
public void run() {
    while(running && (!eof)){
        if(surfaceHolder.getSurface().isValid()){
            Canvas canvas = surfaceHolder.lockCanvas();
            paint(canvas);
            surfaceHolder.unlockCanvasAndPost(canvas);  
        }
    }
    thread = null;
}

where paint(canvas) calls a bunch of other functions that draw a graph and text, for example

canvas.drawText("Time="+myRecord.getMyTime(), 100, 100, paint);

The problem I'm having is that the graph and the text, both of which should be constantly changing, don't get erased but instead keep drawing over themselves. Shouldn't my entire canvas get redrawn every time because that's how double buffering works with the lock() and unlock()? Am I not understanding this correctly? How am I supposed to do this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kalina
  • 5,504
  • 16
  • 64
  • 101
  • Do not tag [SOLVED] in the title. This isn't a forum or something. Post an answer and accept it. Or ask @mibollma to repost the comment as an answer so that you can accept it. – BalusC Aug 02 '11 at 23:03

1 Answers1

2

You need to clear the Canvas yourself after lockCanvas() using Canvas.drawColor().

This might be relevant too:

The content of the Surface is never preserved between unlockCanvas() and lockCanvas(), for this reason, every pixel within the Surface area must be written. The only exception to this rule is when a dirty rectangle is specified, in which case, non-dirty pixels will be preserved.

Source

mibollma
  • 14,959
  • 6
  • 52
  • 69