android surfaceview onDraw vs thread.onDraw
What is better for a android game to use:
a
SurfaceView
with a rendering threador
a
SurfaceView
with a thread that 开发者_如何学运维calls theSurfaceView
functiondoDraw()
Thanks.
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().
精彩评论