开发者

android surfaceview onDraw vs thread.onDraw

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.


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().
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜