1

i have red around that surfaceview work faster in rendering, but take more resources than a view.

from my testing, i tried this code:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawColor(Color.WHITE);
    Log.i("OnDraw","ping");
    invalidate();
}

one is a surfaceview class render, and another is a view class render, both had this same code in them. and from the log chat, i could see that the message from the Log.i method, was refreshing faster in a view class - around 70 milliseconds delay between each one, while in the case of the surfaceView, it refreshed slower - around 100 milliseconds delay between each one.

so... what gives?

Daniel Mendel
  • 506
  • 5
  • 17
  • Based on the refresh times I'm guessing your running in an emulator? My advice for 2D drawing apps on Android: run them on a real phone for debugging and profiling. Performance on a real phone is different from an emulator. Also try running it on a phone before you start optimizing performance - in my experience 2D drawing performance on a phone with SurfaceView is pretty good. I know this doesn't really answer your question, but just figured I'd give you some (anecdotal) advice since I've been down this path recently. – Ivan Sep 20 '12 at 20:29
  • That was my guess too, i did notice there is a difference in performance over a phone and an emulator, I'll guess i will need to install my phone to debug it directly on him now to see for my self :) – Daniel Mendel Sep 20 '12 at 20:33

2 Answers2

1

The main advantage of a SurfaceView is that one can draw on it from a different thread. So, for realtime games you will certainly want SurfaceView or even GLSurfaceView. For games like cards and dominoes Views will be probably fine same as for non-gaming applications

Regarding drawing mechanisms I believe there's nothing which specifically makes SurfaceView faster although since a normal View can only be updated from UI thread SurfaceView often is the only choice.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

After testing the same code on a real phone with debugging, i can say there is no a large visible difference in refresh speed for both view and a surfaceview, although there is a big improvement over an emulator, they both were refreshing at about 20 millisecond.

Daniel Mendel
  • 506
  • 5
  • 17