title: Android: Animation and multithreading
body: <p>i am trying to implement a multithreading in my app and i would like to know how i can do this. Basically in a single view i have 2 blocks i want these two block to bounce around the screen however i want each block to be running on its own thread. So single view multi-thread...if that's  possible. Here's what i have so far:</p>
  
  <pre><code>public class mainActivity extends Activity {
  
  
  protected static final int GUIUPDATEIDENTIFIER = 0x101;
  
  //Thread myRefreshThread = null;
  
  BounceView myBounceView = null;
  
  Handler myGUIUpdateHandler = new Handler() {
  
      @Override
      public void handleMessage(Message msg){
          switch (msg.what){
          case mainActivity.GUIUPDATEIDENTIFIER:
              myBounceView.invalidate();
              break;
          }
          super.handleMessage(msg);
      }
  };
  
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  
      this.myBounceView = new BounceView(this);
      this.setContentView(this.myBounceView);
  
      new Thread (new RefreshRunner()).start();
  
  }
  
  class RefreshRunner implements Runnable {
      // @Override
      public void run() {
              while (!Thread.currentThread().isInterrupted()) {
                      // Send Message to the Handler which will call the invalidate() method of the BoucneView
                      Message message = new Message();
                      message.what = mainActivity.GUIUPDATEIDENTIFIER;
                      mainActivity.this.myGUIUpdateHandler.sendMessage(message);
  
                      try {
                              Thread.sleep(100); // a 10th of a second
                      } catch (InterruptedException e) {
                              Thread.currentThread().interrupt();
                      }
              }
      }
  }
  
  
  }
  </code></pre>
  
  <p>My BounceView is:</p>
  
  <pre><code>public class BounceView extends View {
  
  
  protected Drawable mySprite;
  protected Point mySpritePos = new Point(0,0);
  
  protected enum HorizontalDirection {LEFT, RIGHT}
  protected enum VerticalDirection {UP, DOWN}
  protected HorizontalDirection myXDirection = HorizontalDirection.RIGHT;
  protected VerticalDirection myYDirection = VerticalDirection.UP;
  
  
  public BounceView(Context context) {
          super(context);
  
          this.mySprite = this.getResources().getDrawable(R.drawable.block);
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
          /* Check if the Ball started to leave
           * the screen on left or right side */
          if (mySpritePos.x &gt;= this.getWidth() - mySprite.getBounds().width()) {
                  this.myXDirection = HorizontalDirection.LEFT;
          } else if (mySpritePos.x &lt;= 0) {
                  this.myXDirection = HorizontalDirection.RIGHT;
          }
  
          /* Check if the Ball started to leave
           * the screen on bottom or upper side */
          if (mySpritePos.y &gt;= this.getHeight() - mySprite.getBounds().height()) {
                  this.myYDirection = VerticalDirection.UP;
          } else if (mySpritePos.y &lt;= 0) {
                  this.myYDirection = VerticalDirection.DOWN;
          }
  
          /* Move the ball left or right */
          if (this.myXDirection == HorizontalDirection.RIGHT) {
                  this.mySpritePos.x += 10;
          } else {
                  this.mySpritePos.x -= 10;
          }
          /* Move the ball up or down */
          if (this.myYDirection == VerticalDirection.DOWN) {
                  this.mySpritePos.y += 10;
          } else {
                  this.mySpritePos.y -= 10;
          }
  
          /* Set the location, where the sprite
           * will draw itself to the canvas */
          this.mySprite.setBounds(this.mySpritePos.x, this.mySpritePos.y,
                          this.mySpritePos.x + 50, this.mySpritePos.y + 50);
  
          /* Make the sprite draw itself to the canvas */
          this.mySprite.draw(canvas);
   }
  }
  </code></pre>
  
  <p>So this works perfectly however this only handles a single block. I would like to add a secondary block (using the same graphic) that is handled by a separate thread. How can i do this? do i have to make a separate view for the other block?</p>