When I finishing my activity, should I use clearAnimation()
or stop()
on any remaining AnimationDrawable
objects?
Asked
Active
Viewed 7,799 times
8

ankuranurag2
- 2,300
- 15
- 30

Ranjit
- 209
- 5
- 12
-
check this link [enter link description here][1] [1]: http://stackoverflow.com/questions/4112599/how-to-stop-animation-cancel-does-not-work – user1203673 Feb 22 '12 at 09:43
-
I suppose stop() means end the Animation, and the Animation still be related to the view. While clearAnimation may cancel the animation relative to the view. I haven't test it, just my guess – JohnCookie Feb 22 '12 at 09:46
1 Answers
4
stop()
stops the animation and that's all. Since stop() is method of AnimationDrawable.class
you can use it when you want to stop the animation of AnimationDrawable
, but not on any View.
clearAnimation()
is method of the View.class
. It will stop the animation of the View and additionally:
If there is
AnimationListener
defined,AnimationListener.onAnimationEnd(Animation animation)
will be called.If there is
Handler
definedHandler.postAtFrontOfQueue(Runnable r)
will be called.
Here is the call hierarchy:
View.clearAnimation()
-> Animation.detach()
-> Animation.fireAnimationEnd()
and the fireAnimationEnd()
method:
private void fireAnimationEnd() {
if (mListener != null) {
if (mListenerHandler == null) mListener.onAnimationEnd(this);
else mListenerHandler.postAtFrontOfQueue(mOnEnd);
}
}

Ivo Stoyanov
- 16,256
- 8
- 62
- 65
-
I used `view.setAnimation(null)` in my case. Neither stop or clearAnimation was doing what I needed. – James Dec 27 '19 at 13:51