Code example for SurfaceHolder

Methods: getSurface

    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
         * If your preview can change or rotate, take care of those events here. 
         * Make sure to stop the preview before resizing or reformatting it. 
        if (mHolder.getSurface() == null){
          // preview surface does not exist 
        // stop preview before making changes 
        try { 
        } catch (Exception e){
          // ignore: tried to stop a non-existent preview 
        try { 
            // Hard code camera surface rotation 90 degs to match Activity view in portrait 
Contextual code suggestions in your IDE  Get Codota for Java