How to cancel the animation, but not finish it?

I have a TranslateAnimation class in my class. Animation starts automatically.

I set the button so that if it is pressed, the animation will be canceled ( animation.cancel(); ).

I also installed AnimationListener for my class. If my animation ends, I will start a new action (you will go to the menu).

 public void onAnimationEnd(Animation animation) { startActivity(new Intent(Class.this, Class2.class)); } 

My application relies on the user to press a button before the animation ends. The problem is that animation.cancel(); allowed as end of animation.

How to cancel the animation in another way that was not taken into account as the end of the animation? Is it possible?

Thanks in advance!

+4
source share
2 answers

animation.cancel () calls the animation listener as the API Documentation describes :

Canceling an animation causes the animation listener, if installed, to notify the end of the animation. If you cancel the animation manually, you must call reset () before restarting the animation.

If you want a different behavior when undoing () and onAnimationEnd (), I would suggest a boolean variable that can be set when the button is clicked, and onanimationend checks to see if it is true.

+2
source

After canceling the animation, you can remove the listener, thereby preventing the call to onAnimationEnd :

 @Override public void onAnimationCancel(Animator animation) { animation.removeAllListeners(); } 
+19
source

All Articles