Reputation: 21
I have the following animation set in onClick. I am trying to start my activity after the animation is done, but it isn't working.
CODE
final ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
iv1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Animation anim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);
iv1.startAnimation(anim);
Intent i = new Intent();
i.setClass(MainActivity.this, P2.class);
startActivity(i);
}
});
QUESTION
How do I wait for the animation to complete before starting my activity?
Upvotes: 0
Views: 1242
Reputation: 4981
You can use AnimationListner for this. http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html
Here's an example: https://stackoverflow.com/a/8860057/3864698
Upvotes: 0
Reputation:
Use animation listener
Animation.AnimationListener listener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Intent i = new Intent();
i.setClass(MainActivity.this, P2.class);
startActivity(i);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
};
anim.setAnimationListener(listener);
iv1.startAnimation(anim);
Upvotes: 2