Double buffering in Java on Android with canvas and surfaceview

Kalina picture Kalina · Jun 30, 2011 · Viewed 15.8k times · Source

How does one go about doing this? Could somebody give me an outline?

From what I've found online, it seems like in my run() function:

  1. create a bitmap
  2. create a canvas and attach it to the bitmap
  3. lockCanvas()
  4. call draw(canvas) and draw bitmap into back buffer (how??)
  5. unlockCanvasAndPost()

Is this correct? If so, could I get a bit of an explanation; what do these steps mean and how do I implement them? I've never programmed for Android before so I'm a real noob. And if it isn't correct, how DO I do this?

Answer

Romain Guy picture Romain Guy · Jun 30, 2011

It's already double buffered, that's what the unlockCanvasAndPost() call does. There is no need to create a bitmap.