Animation BEFORE a change in activity

I am trying to do something simple, but I can’t understand why it is not working.
I am trying to do the following: when I touch ImageView, it will show the animation. And then, only when this animation is over, will it start a new activity.
Instead, what happens is that a new action starts immediately, and the animation is not displayed.

Here is the xml animation:

<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 that 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 can see, I tried to impose time for the animation, but this will not work. NextActivity starts right away; it does not wait for the animation to complete in ThisActivity.
Any idea on why this is happening?

+5
source share
2 answers

, . , :

@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
+4
+2

All Articles