Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between clearAnimation() and stop() in android?

When I finishing my activity, should I use clearAnimation() or stop() on any remaining AnimationDrawable objects?

like image 850
Ranjit Avatar asked Feb 22 '12 09:02

Ranjit


1 Answers

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 defined Handler.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);
    }
}
like image 127
Ivo Stoyanov Avatar answered Oct 18 '22 00:10

Ivo Stoyanov