Android onAnimationEnd called twice

android onanimationend not called
onanimationend not called react
android animation
android view animation
valueanimator offloat android

i have created a SLIDE UP animation on view and i am repeating this animation again onAnimationEnd but my onAnimationEnd fired twice , i have checked it with counter at onAnimationEnd , i will post my code, you can check that the counter in onAnimationEnd will incremented twice at same time , I am starting the animation again in onAnimationEnd method , please guide me where i am doing wrong?

    private Animation animSlideUp;
        animSlideUp = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_up);
                // set animation listener
                animSlideUp.setAnimationListener(this);
                animSlideUp.setDuration(500);
                animSlideUp.setStartOffset(5000);

                tickerView.startAnimation(animSlideUp);

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (animation == animSlideUp) {
                ticker_counter++;
                Log.e("onAnimationEnd=", "ticker_counter="+ticker_counter);
                tickerView.startAnimation(animSlideUp);

            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

slide_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <scale
        android:duration="500"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXScale="1.0"
        android:toYScale="0.0"/>

</set>
LOGCAT

    11-19 17:06:54.375   E/onAnimationEnd=﹕ ticker_counter=1
    11-19 17:06:54.392   E/onAnimationEnd=﹕ ticker_counter=2
    11-19 17:06:59.912   E/onAnimationEnd=﹕ ticker_counter=3
    11-19 17:06:59.928   E/onAnimationEnd=﹕ ticker_counter=4
    11-19 17:07:05.453   E/onAnimationEnd=﹕ ticker_counter=5
    11-19 17:07:05.470   E/onAnimationEnd=﹕ ticker_counter=6
    11-19 17:07:10.991   E/onAnimationEnd=﹕ ticker_counter=7
    11-19 17:07:11.008   E/onAnimationEnd=﹕ ticker_counter=8

If you want your animation to play once, you have to remove tickerView.startAnimation(animSlideUp); from the onAnimationEnd Method. Avoid using xml animations, it's much easier in java code. If you're trying to animate two properties :

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("scaleX", 1.0f, 0);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleY", 1.0f, 0);
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(tickerView, pvhX, pvhY);
        animator.setDuration(500);
        animator.start();

In your case, you're only changing the scaleY value from 1.0 to 0, so use this :

ObjectAnimator animator = ObjectAnimator.ofFloat(tickerView, "scaleY",0);
animator.setDuration(500);
//To repeat twice if you want to
animator.setRepeatCount(1);
animator.start();

LinearInterpolator is used by default.

Repeat after every 5 sec

    final ObjectAnimator animator = ObjectAnimator.ofFloat(tickerView, "scaleY", 0);
    animator.setDuration(500);
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            ticker_counter++;
            animation.setStartDelay(5000);
            animator.start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    animator.start();

onAnimationEnd called twice when system animations are disabled , module may be auto-closed. Link to fork with a repro in the issue-repro module https://github.com/BoD/lottie-android/blob/master  If an animation is run on the same view twice, onAnimationEnd() is not called the second time. #1809 erichaugh opened this issue May 14, 2015 · 5 comments Labels


I may found the solution: post an runnable to restart the animation.

In your case , in OnAnimationEnd() function, code like this:

 @Override
    public void onAnimationEnd(Animation animation) {
        if (animation == animSlideUp) {
            ticker_counter++;
            Log.e("onAnimationEnd=", "ticker_counter="+ticker_counter);
            tickerView.post(new Runnable(){ //post an runnable to start
                tickerView.startAnimation(animSlideUp);
            });

        }
    }

If an animation is run on the same view twice, onAnimationEnd() is , the same view twice, onAnimationEnd() is not called the second time. Android animation code expects and what Robolectric actually does,  AnimatorListenerAdapter extension to bypass android 4.0.x bug where each method was called twice - OneShotCancelableAnimatorListenerAdapter


I had the same problem, I removed

android:animateLayoutChanges="true" 

from the xml file and it helped

onAnimationStart and onAnimationEnd are getting , Android: onAnimationStart and onAnimationEnd are getting executed twice for custom LinearLayout After calling hide() afterwards, views are hidden correctly. twice - android animation is not finished in onAnimationEnd on animation end android (8) It seems that an android animation is not truly finished when the onAnimationEnd event is fired although animation.hasEnded is set to true.


I had the same problem and just setting null as listener of second animation worked for me.

setListener(null);

Example:

view.animate()
    .alpha(0F)
    .setDuration(200L)
    .setListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {

            view.animate()
                .alpha(1F)
                .setDuration(200L)
                .setListener(null)
                .start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

    }).start();

Animation.AnimationListener, public abstract void onAnimationEnd (Animation animation). Notifies the end of the animation. This callback is not invoked for animations with  Android for some reason calls onPageFinished () twice (and onPageStarted () three times!) when the loaded url is not a working one. The temporary solution is changing the redirect_uri to the url of a working website; in this case, I changed it to https://www.google.com/ (lol, sorry Google). onPageFinished is then only called once.


OnAnimationEnd animation.setAnimationListener is called the two , OnAnimationEnd animation.setAnimationListener is called the two update. Label AnimationSetAnimationListenerOnAnimationEndtwice In the implementation of the cancel and later called a onAnimationEnd., so the lateral fill; Next article​Android source code compiler: any interface on the edge of the  Description The OnAppearing method is being called twice for the child tab contentpage that is being displayed when TabbedPage is set as main page of application.


How to use Android animation listeners, This tutorial shows how to use Android animation listeners when simple time-​based Next we need to create a new directory in the /res folder called /anim -- this is where we place publicvoid onAnimationEnd(Animation a) { Here is an example of what doesn&#39;t work. Discovered when trying to migrate from 2.4 to 3.0 @Test public void start_shouldRunAnimationAndFireStartAndEndCallbacks


#16347 (dojox/mobile/View always sets paddingTop in , In chrome and Android 4 (not tested in other browsers), this padding top is not If you call performTransition(), onAnimationEnd will be called twice, one for  Summary: For returnKeyType 'go', 'search' and 'send' Android will call onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION. This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.