Reputation: 3349
What is better for a android game to use:
a SurfaceView
with a rendering thread
or
a SurfaceView
with a thread that calls the SurfaceView
function doDraw()
Thanks.
Upvotes: 2
Views: 3675
Reputation: 40391
The drawing in a SurfaceView
is already handled in a separate thread. You do not need to spawn a new one.
See the API doc about it:
One of the purposes of this class is to provide a surface in which a secondary thread can render into the screen. If you are going to use it this way, you need to be aware of some threading semantics:
- All SurfaceView and SurfaceHolder.Callback methods will be called from the thread running the SurfaceView's window (typically the main thread of the application). They thus need to correctly synchronize with any state that is also touched by the drawing thread.
- You must ensure that the drawing thread only touches the underlying Surface while it is valid -- between SurfaceHolder.Callback.surfaceCreated() and SurfaceHolder.Callback.surfaceDestroyed().
Upvotes: 1