Surface Creation and Validity

We cannot acquire the Canvas from the SurfaceHolder as long as the Surface is not yet valid. However, we can check whether the Surface has been created or not via the following statement:

boolean isCreated = surfaceHolder.getSurface().isValid();

If this method returns true, we can safely lock the surface and draw to it via the Canvas we receive. We have to make absolutely sure that we unlock the Surface again after a call to SurfaceHolder.lockCanvas(), or else our activity might lock up the phone!

0 0

Post a comment