android updateThread draw() method and touchEvent interference
<p>I have a game which displays an array of colored blocks. The user can move these blocks around the screen. When a touch event occurs, I take note of the cell that has been touched (<code>cell[i][j].isMoving = true</code>). If the user moves the block around I draw the rectangle relative to an offset value. When a touch up event is detected, I check whether or not the user has dragged the block far enough to signify a moving of a block.</p>

<p>My basic draw loop is as follows:</p>

<pre><code>for(int i = 0; i &lt; xCells, i++){
   for(int j = 0; j &lt; yCells; j++){
       if(cell[i][j].isMoving)
             canvas.drawRect(...) // draw with offsets
       else
             canvas.drawRect(..)
      }
 }
</code></pre>

<p>The problem I am having is when a user releases the block it occasionally flickers briefly.</p>

<p>When a touch up event occurs, the offset must be set to 0, the coordinates of the block changed (if requirements are met) and <code>isMoving</code> has to be set to <code>false</code>. 
As I have a thread constantly running that calls the draw code above, it appears that the UI thread is altering the array of blocks, meaning it is in an inconsistent state when the draw method occurs.</p>

<p>Does anyone have suggestions on how to fix this? Could I use a handler? I've tried synchronizing the <code>onTouchEvent</code> method and the <code>onDraw</code> method, but this seems to occasionally block user input</p>

<p>thanks</p>
