title: Drawing on a canvas using a holder and a separate thread does not show anything on the screen
body: <p>I wanted to use a SurfaceView with a "sticky" canvas. i.e. one that preserves its state and does not get ivalidated. I followed an example that showed how to set up a holder and use a separate thread for the drawing. The idea is that when touching anywhere on the SurfaceView, <code>drawStuff</code> will be called, given some paint, and a random rectangle should be drawn. </p>
  
  <p>Although the code executes perfectly, nothing is drawn at the end.</p>
  
  <pre><code>public class DrawingView extends SurfaceView implements Callback {
  
      Paint currentPaint;
      float verts[];
      private Boolean drawing = false;
  
      class DrawingThread extends Thread {
          private SurfaceHolder surfaceHolder;
          private SurfaceView surfaceView;
          private Boolean isRunning = false;
  
          public void setIsRunning(Boolean isRunning) {
              this.isRunning = isRunning;
          }
  
          public DrawingThread(SurfaceHolder surfaceHolder, SurfaceView surfaceView) {
              super();
              this.surfaceHolder = surfaceHolder;
              this.surfaceView = surfaceView;
          }
  
  
          @Override
          public void run() {
              while(isRunning) {
                  Canvas c = surfaceHolder.lockCanvas();
                  surfaceView.draw(c);
                  surfaceHolder.unlockCanvasAndPost(c);
              }
          }
      }
  
      DrawingThread thread;
  
  
      public DrawingView(Context context) {
          super(context);
          this.setWillNotDraw(false);
          this.setBackgroundColor(Color.WHITE);
  
          this.getHolder().addCallback(this);
          this.thread = new DrawingThread(getHolder(), this);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
  
          if (drawing) {
              // TEST CODE. WILL NEVER USE THIS IN PRODUCTION
              canvas.drawRect(new Rect(new Float(Math.random()*200).intValue(), 20, new Float(Math.random()*200).intValue(), 30), currentPaint);
              drawing = false;
          }
  
      }
  
  
      public void drawStuff(Paint paint) {
          currentPaint = paint;
  
          drawing = true;
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width,
              int height) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder holder) {
          thread.setIsRunning(true);
          thread.start();
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) {
          thread.setIsRunning(false);
  
      }
  
  
  }
  </code></pre>
  
  <p>and the paint set up:</p>
  
  <pre><code>view.setOnTouchListener(new View.OnTouchListener() {
  
      @Override
      public boolean onTouch(View v, MotionEvent event) {
  
          Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
          paint.setStyle(Paint.Style.FILL);
          paint.setColor(Color.BLUE);
          paint.setAlpha(55);
  
          ((DrawingView) v).drawStuff(paint);
  
          //v.invalidate();
  
          return false;
      }
  });
  </code></pre>