blejzz
blejzz

Reputation: 3349

android surfaceview onDraw vs thread.onDraw

What is better for a android game to use:

Thanks.

Upvotes: 2

Views: 3675

Answers (1)

Aleadam
Aleadam

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

Related Questions