How to know when lottie animation is completed?
This code works for me:
mAddedToCartAnimation.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
Log.e("Animation:","start");
}
@Override
public void onAnimationEnd(Animator animation) {
Log.e("Animation:","end");
//Your code for remove the fragment
try {
getActivity().getSupportFragmentManager()
.beginTransaction().remove(this).commit();
} catch(Exception ex) {
ex.toString();
}
}
@Override
public void onAnimationCancel(Animator animation) {
Log.e("Animation:","cancel");
}
@Override
public void onAnimationRepeat(Animator animation) {
Log.e("Animation:","repeat");
}
});
I hope this solve your problem :)
Kotlin Code for animation complete :
successAnimation.addAnimatorListener(object : Animator.AnimatorListener{
override fun onAnimationRepeat(animation: Animator?) {
}
override fun onAnimationEnd(animation: Animator?) {
//Add your code here for animation end
}
override fun onAnimationCancel(animation: Animator?) {
}
override fun onAnimationStart(animation: Animator?) {
}
})