Reputation: 6188
I would like to perform an animation on an image before switching to a new activity. I also want to make sure that the animation is fully completed before the new activity starts. Below is the code that I am using to accomplish the task.
public boolean onTouch(View view, MotionEvent event) {
Animation shake = AnimationUtils.loadAnimation(ViewReadingActivity.this, R.anim.shake);
imgAries.startAnimation(shake);
Intent intent = new Intent(ViewReadingActivity.this, ShowHoroActivity.class);
startActivity(intent);
return true;
}
The problem with this is that the animation does not run to completion before the new activity is presented and the animation will continue to run from where it was left. Is there a better way to accomplish this?
Upvotes: 1
Views: 1562
Reputation: 10856
use like this here you can have animation listner
shake.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
Intent intent = new Intent(ViewReadingActivity.this, ShowHoroActivity.class);
startActivity(intent);
}
});
Upvotes: 7
Reputation: 4762
Animation Listener Already Contains the Method called as onAnimationEnd @override it on your imgAries Animation Listener
onAnimationEnd(Animation anim){
//Start you Activity here using Intent
Intent i=new Intent(this,//Your next Activity);
startActivity(i);
}
That it...Now you can go to Next Activity on Animation End...Thks
Upvotes: 1
Reputation: 7259
do this: 1. animation.setAnimationListener(), implement the methods 2. onanimationend method , write in the code to start a new activity
m late :(
Upvotes: 1