title: How to change attributes of the second Activity from Main activity?
body: <p>In the main activity I have a handler to exchange messages with the bluetooth service. This works fine.
  Now, I want launch second activity (SurfaceViewAnimation). I do this with:</p>
  
  <blockquote>
    <p>startActivity (new Intent (this, SurfaceViewAnimation.class));</p>
  </blockquote>
  
  <p>but I want change some attributes of SufaceViewAnimation class from main activity when it receives a command for bluetooth.</p>
  
  <p><strong>How I can do this?</strong></p>
  
  <p>The code of SufaceViewAnimation class is:</p>
  
  <pre><code>    class BouncingBallView extends SurfaceView implements SurfaceHolder.Callback {
  
      private BouncingBallAnimationThread bbThread = null;
  
      private int xPosition = getWidth()/2;
      private int yPosition = getHeight()/2;
      private int xDirection = 20;
      private int yDirection = 40;
  
      private static int radius = 20;
      private static int ballColor = Color.RED;
  
      public BouncingBallView(Context ctx, AttributeSet attrs, int defStyle) {
              super(ctx, attrs, defStyle);
              getHolder().addCallback(this);
      }
  
      public void onDraw(Canvas canvas) {
              super.onDraw(canvas);
              Paint paint = new Paint();
              paint.setColor(Color.BLACK);
              canvas.drawRect(0,0,getWidth(),getHeight(), paint);
              paint.setColor(ballColor);
              canvas.drawCircle(xPosition, yPosition, radius, paint);
      }
  
      public void surfaceCreated(SurfaceHolder holder) {
              if (bbThread!=null) return;
              bbThread = new BouncingBallAnimationThread(getHolder());
              bbThread.start();
      }
  
      public void surfaceChanged(SurfaceHolder holder,int format, int width, int height) {  }
  
      public void surfaceDestroyed(SurfaceHolder holder) {
              bbThread.stop = true;
      }
  
      private class BouncingBallAnimationThread extends Thread {
  
              public boolean stop = false;
              private SurfaceHolder surfaceHolder;
  
              public BouncingBallAnimationThread(SurfaceHolder surfaceHolder) {
                      this.surfaceHolder = surfaceHolder;
              }
  
              public void run() {
                      while (!stop) {
                              xPosition += xDirection;
                              yPosition += yDirection;
                              if (xPosition&lt;0) {
                                      xDirection = -xDirection;
                                      xPosition = radius; }
                              if (xPosition&gt;getWidth()-radius) {
                                      xDirection = -xDirection;
                                      xPosition = getWidth()-radius; }
                              if (yPosition&lt;0) {
                                      yDirection = -yDirection;
                                      yPosition = radius; }
                              if (yPosition&gt;getHeight()-radius) {
                                      yDirection = -yDirection;
                                      yPosition = getHeight()-radius-1; }
  
                              Canvas c = null;
                              try {
                                      c = surfaceHolder.lockCanvas(null);
                                      synchronized (surfaceHolder) {
                                              onDraw(c);
                                      }
                              } finally {
                                      if (c != null) surfaceHolder.unlockCanvasAndPost(c);
                              }
                      }
              }
  
      }
  
      public boolean onTouchEvent(MotionEvent event) {
  
         if (event.getAction() != MotionEvent.ACTION_DOWN) return false;      
         if (xDirection!=0 || yDirection!=0)      
               xDirection = yDirection = 0;       
         else {       
               xDirection = (int) event.getX() - xPosition;       
               yDirection = (int) event.getY() - yPosition;
         }    
         if(ballColor==Color.RED)
             ballColor=Color.GREEN;
         else
             ballColor=Color.RED;
         return true;     
      }
  
      public void setxDirection(int xDirection) {
          this.xDirection = xDirection;
      }
  
      public void setyDirection(int yDirection) {
          this.yDirection = yDirection;
      }
  
      public void setballColor(int ballColor) {
          this.ballColor = ballColor;
      }
  
      public void setradius(int radius) {
          this.radius = radius;
      }
  }
  
  public class SurfaceViewAnimation extends Activity {
          public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(new BouncingBallView(this,null,0));
          }
  }
  </code></pre>