0

i have three functions- animation, sound, vibration. all these work perfectly fine individually. i need to start all these 3 functions together and continue playing for 3 seconds and then stop. i want this to repeat after every 15 seconds. what will be the correct approach to implement this? my vibration code is as follows

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);

}

animation code:

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();     
 }

sound using soundpool:

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
}
Triode
  • 11,309
  • 2
  • 38
  • 48
newbee
  • 409
  • 2
  • 12
  • 34
  • you can use countdownTimer., for every tick ie) you can set every tick for 15 sec and do your required in onTick() method.right? – Tamilselvan Kalimuthu Mar 11 '13 at 11:25
  • @Tamilselvan could you provide me with a code snippet on how to implement this? i have very little knowledge on using threads n timers. thankyou. – newbee Mar 11 '13 at 11:31
  • 1
    @newtoandroid Why did you make a duplicate? http://stackoverflow.com/questions/15335791/perform-functions-synchronously You already have 3 answers there. – Simon Zettervall Mar 11 '13 at 11:57
  • @SimonZettervall simply because i did not get a suitable answer there. if u have any solution kindly help – newbee Mar 11 '13 at 12:06
  • OP: Please stop posting a duplicate question which is why I vc'd this one! If the original [question](http://stackoverflow.com/questions/15335791/perform-functions-synchronously) does not satisfy, explain, re-edit the question, clarify. – t0mm13b Aug 15 '13 at 17:51

1 Answers1

0

you need to implement thread to run all together for specified time.

Thread myTime = new Thread()
{
      void run(){
           sleep(3000) //sleep untill 3 sec than stop 
           //your code
      }
}