title: perform functions synchronously
body: <p>i have a few functions that have to be implemented synchronously for 3 seconds. i have a sound being played using soundpool, a vibration pattern, and a background animation. all three of them work fine separately. but i am not able to time them properly so that all start together.</p>
  
  <p>these 3 functions need to be called repeatedly after every 15 seconds. and will be stopped on a button click.  i tried using something like this, but it doesnt work properly.</p>
  
  <pre><code> myThread = new Thread(new Runnable(){
  
              @Override
              public void run() {
                  // TODO Auto-generated method stub
  
                  while (shouldRun==true) {
                      try {                      
                          mHandler.post(new Runnable() {
  
                              @Override
                              public void run() {
  
                                  anim();
                                  vibration();
                                  sound();
  
  
  
                              }
                          });
                          mHandler.postDelayed(new Runnable() {
                              public void run(){
                              try {
                                  Thread.sleep(15000);
                              } catch (InterruptedException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                              }
                              }
                          }, 3000);
                      } catch (Exception e) {
                          // TODO: handle exception
                      }
                  }               
              }// end of outer run()          
          });
          myThread.start();
  </code></pre>
  
  <p>is this the right way to do it? or is there some other way? </p>
  
  <pre><code>public void vibration(){            
      int dash = 1000;    
      int medium_gap = 500;
  
      long[] pattern = { 0,  // Start immediately
          dash, medium_gap,dash , medium_gap
      };
      // Only perform this pattern one time (-1 means "do not repeat")
      v.vibrate(pattern, -1);
  
  }
  
  
  linear = (LinearLayout) findViewById(R.id.lay);// this line is after setContentView in onCreate
  public void anim(){
  
          drawable.addFrame(new ColorDrawable(Color.RED), 1000);  
          drawable.addFrame(new ColorDrawable(Color.WHITE), 500);         
          drawable.setOneShot(false);     
          linear.setBackgroundDrawable(drawable);         
          drawable.start(); 
  
      }
  
  sp = new SoundPool(5, AudioManager.STREAM_NOTIFICATION, 0);
  buzzer = sp.load(this, R.raw.buzzer, 0);
  public void sound(){
          sp.play(buzzer, 1,1, 0, 0, 1); //start alert tone
      }
  </code></pre>