ValueAnimator doesn't work as expected when battery saver is enabled(>= API 21)

橙三吉。 提交于 2019-12-11 08:46:07

问题


ValueAnimator doesn't seem to repeat or play animators that are repeated infinitely when the battery saver is enabled in Android lollipop or higher.

    animator = ValueAnimator.ofInt(0,timePeriods.length-1);
    animator.setInterpolator(new LinearInterpolator());
    animator.setEvaluator(new TypeEvaluator() {
        @Override
        public Object evaluate(float v, Object o, Object t1) {
            int time = 0 ;
            int timeElapsed = (int)(v*totalTime) ;
            for (int i = 0; i < timePeriods.length; i++) {
                time = time + timePeriods[i];
                if(time>=timeElapsed) return i ;
            }
            return 0 ;
        }
    });
    animator.setDuration(totalTime);
    animator.setRepeatCount(repeatCount);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        int currentValue = -1 ;
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();
            if(value!=currentValue){
                Log.d(TAG,"Value Changed: "+currentValue+" "+value);
                currentValue = value ;
            }
        }
    });

When the battery saver is enabled the animator plays the animation only once and doesn't repeat after that... Is there any setting|Flag within the application or activity to run animators even in low battery mode as the above animator is a simple integer valueanimator and doesn't drain the battery any further.

来源:https://stackoverflow.com/questions/38483783/valueanimator-doesnt-work-as-expected-when-battery-saver-is-enabled-api-21

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!