0

Can these two expressions both be true at one time? holder.getSurface().isValid() == true; and canvas = holder.lockCanvas() canvas == null;

1 Answer 1

1

From references:

isValid() - Does this object hold a valid surface? Returns true if it holds a physical surface, so lockCanvas() will succeed.

So, if lockCanvas() succeeds it returns a non null canvas.

But you shouldn't access Surface directly (you need synchronization), in surfaceChanged you can just call canvas = holder.lockCanvas() and draw only if canvas is not null.

Sign up to request clarification or add additional context in comments.

2 Comments

Is it meen that I need to implement SurfaceHolder.Callback and check drawing possibility in surfaceCreated method?
the SurfaceHolder is initialized asynchronous so, basicaly if you want to draw on it you should have a SurfaceHolder.Callback (to know when it is ready), and the best place to do the drawings is in surfaceChanged (which is called after surfaceCreated) and where you are provided with width, height and holder.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.