Victoria Seniuk
Victoria Seniuk

Reputation: 1414

Android Canvas is null

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

Upvotes: 0

Views: 1334

Answers (1)

ALiGOTec
ALiGOTec

Reputation: 347

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.

Upvotes: 1

Related Questions