Ganjira Ganjira - 2 months ago 23
Android Question

How to cancel an animation, but not to end it?

I have a

on my class. The animation starts automatically.

I set button that if it is clicked, the animation will be canceled (

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

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

My app is relying on that the user has to click the button before the animation ends.
The problem is that
is admitted as the end of the animation.

How to cancel the animation in the other way that was not counted as the end of the animation? Is that possible?

Thanks in advance!


animation.cancel() is calling the animation listener as API documentation describes:

Cancelling an animation invokes the animation listener, if set, to notify the end of the animation. If you cancel an animation manually, you must call reset() before starting the animation again.

If you want different behaviour on cancel() and onAnimationEnd() i would suggest a boolean variable, which can be set on button click, and onanimationend checks whether it is true.