In my activity i am playing animations.. When i am starting the activity for first time,all the animations are playing with the given duration. But it is speed up when i am repeating each and every animation for more time.. This is my activity…. And In my code i haven’t provide all object and variable declaration to reduce the code…
public class Exercise extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.exercise);
exercise_Layout=(RelativeLayout)findViewById(R.id.exerciselayout);
exercise_Layout.setBackgroundResource(R.drawable.exercise_bg);
if(getIntent().getStringExtra("TIPS").equals("Fun"))
{
count=0;
System.out.println("This is Fun");
}
else if(getIntent().getStringExtra("TIPS").equals("Tips"))
{
count=1;
}
gym.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
exercise_Layout.setBackgroundResource(R.drawable.exercise_bg);
gym_View.setBackgroundResource(R.anim.gymanim);
gym_Animation=(AnimationDrawable)gym_View.getBackground();
gym_Animation.start();
//playing sounds
mp.reset();
mp=MediaPlayer.create(getApplicationContext(),R.raw.gym);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
mp.setLooping(true);
}
});
run.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
exercise_Layout.setBackgroundResource(R.drawable.exercise_bg);
run_View.setBackgroundResource(R.anim.runanim);
run_Animation=(AnimationDrawable)run_View.getBackground();
run_Animation.start();
//playing sounds
mp.reset();
mp=MediaPlayer.create(getApplicationContext(),R.raw.thread_music);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
mp.setLooping(true);
}
});
jogg.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
jogg_View.setBackgroundResource(R.anim.jogroadanim);
jogg_Animation=(AnimationDrawable)jogg_View.getBackground();
jogg_Animation.start();
//playing sounds
mp.reset();
mp=MediaPlayer.create(getApplicationContext(),R.raw.jogging);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
mp.setLooping(true);
}
});
swim.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
exercise_Layout.setBackgroundResource(R.drawable.swimingpool);
swim_View.setVisibility(View.VISIBLE);
swim_View.setBackgroundResource(R.anim.swimanim);
swim_Animation=(AnimationDrawable)swim_View.getBackground();
swim_Animation.start();
//playing sounds
mp.reset();
mp=MediaPlayer.create(getApplicationContext(),R.raw.swimming);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
mp.setLooping(true);
}
});
}
I´m not sure, but if you use
CountDownTimersand you press multiple times on it, you start them twice or more times. Maybe its the same issue to your animations. I see thereswim_Animation.start();for example.. tryswim_Animation.stop();before reactivating it. I hope I didn’t misunderstand you explanation..