title: Android - draw bitmap on screen on touch event
body: <p>Am new to android development. I am trying to draw a bitmap image whenever the user touches the screen. I have managed to retrieve the x and y position of the touch event that happens on the screen. But I can't figure out why the program mentioned below will not draw the image on the canvas.</p>
  
  <p>Here is the code I am working on:</p>
  
  <pre><code>public class SurfaceViewTest extends Activity implements OnTouchListener {      
  FastRenderView renderView;   
  Bitmap bob565;
  Bitmap bob4444;
  float x,y;
  Canvas canvas = new Canvas();
  
  public void onCreate(Bundle savedInstanceState) {
  
  
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                           WindowManager.LayoutParams.FLAG_FULLSCREEN);
      renderView = new FastRenderView(this);
      setContentView(renderView);
  }   
  
  
  protected void onResume() {
      super.onResume();
      renderView.resume();
  }
  
  protected void onPause() {
      super.onPause();         
      renderView.pause();
  }    
  
  
  public boolean onTouch(View v, MotionEvent event) {
      // TODO Auto-generated method stub
      ;
  switch (event.getAction()) {
  
      case MotionEvent.ACTION_DOWN:
          x = event.getX();
          y = event.getY()
          canvas.drawBitmap(bob4444, x, y, null);
          break;
  
      }
      return true;
  }
  
  
  
  
  class FastRenderView extends SurfaceView implements Runnable {
      Thread renderThread = null;
      SurfaceHolder holder;
      volatile boolean running = false;
  
      public FastRenderView(Context context) {
          super(context);           
          holder = getHolder();    
  
          try {
              AssetManager assetManager = context.getAssets();
              InputStream inputStream = assetManager.open("bobrgb888.png");
              bob565 = BitmapFactory.decodeStream(inputStream);
              inputStream.close();
              Log.d("BitmapText",
                      "bobrgb888.png format: " + bob565.getConfig());
  
              inputStream = assetManager.open("bobargb8888.png");
              BitmapFactory.Options options = new BitmapFactory.Options();
              options.inPreferredConfig = Bitmap.Config.ARGB_4444;
              bob4444 = BitmapFactory.decodeStream(inputStream, null, options);
  
              inputStream.close();
              Log.d("BitmapText",
                      "bobargb8888.png format: " + bob4444.getConfig());
  
          } catch (IOException e) {
  
          } finally {
              // we should really close our input streams here.
          }
      }
  
  
      public void resume() {          
          running = true;
          renderThread = new Thread(this);
          renderThread.start();         
      }      
  
      public void run() {
          while(running) {  
              if(!holder.getSurface().isValid())
                  continue;
  
              Canvas canvas = holder.lockCanvas();            
              canvas.drawRGB(0, 0, 255);    
              canvas.drawBitmap(bob4444, x, y, null);
              holder.unlockCanvasAndPost(canvas);   
  
  
  
          }
      }
  
      public void pause() {                        
          running = false;                        
          while(true) {
              try {
                  renderThread.join();
                  return;
              } catch (InterruptedException e) {
                  // retry
              }
          }      
  
  
         }        
      }
  }
  </code></pre>