I'm trying to do something simple, but I can't understand why it's not working.
What I'm trying to do is: when I touch an ImageView, it will show an animation on it. And then, only when that animation ends it will start the new activity.
Instead, what happens is that the new activity starts right away and the animation is not shown.
Here is the animation xml:
<rotate android:interpolator="@android:anim/decelerate_interpolator"
android:fromDegrees="-45"
android:toDegrees="-10"
android:pivotX="90%"
android:pivotY="10%"
android:repeatCount="3"
android:fillAfter="false"
android:duration="10000" />
And this is the code I use to call it:
public void onCreate( Bundle savedInstanceState )
{
final ImageView ib = (ImageView)this.findViewById( R.id.photo );
ib.setOnClickListener( new OnClickListener( ) {
@Override
public void onClick( View v )
{
Animation hang_fall = AnimationUtils.loadAnimation( Curriculum.this, R.anim.hang_fall );
v.startAnimation( hang_fall );
Intent i = new Intent( ThisActivity.this, NextActivity.class );
ThisActivity.this.startActivity( i );
}// end onClick
} );
}// end onCreate
As you see I tried putting a loooong time for the animation, but it doesn't work. The NextActivity starts right away, it doesn't wait for the animation in ThisActivity to finish.
Any idea on why this happens?
That's because you're starting the intent and the animation at the same time. You need to start the intent after the animation is over, like this:
@Override
public void onClick( View v )
{
Animation hang_fall = AnimationUtils.loadAnimation( Curriculum.this, R.anim.hang_fall );
hang_fall.setAnimationListener(new Animation.AnimationListener()
{
public void onAnimationEnd(Animation animation)
{
Intent i = new Intent( ThisActivity.this, NextActivity.class );
ThisActivity.this.startActivity( i );
}
public void onAnimationRepeat(Animation animation)
{
// Do nothing!
}
public void onAnimationStart(Animation animation)
{
// Do nothing!
}
});
v.startAnimation( hang_fall );
}// end onClick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With