We use AnimatedVectorDrawable.reset()
to reset the animation to its initial state. This works well on most of the devices. While testing we noticed that on some Huawei devices when reset()
is called the animation starts running.
Reproduced on these Huawei devices:
Any ideas what can I do to fix the problem?
To fix the problem I updated the animation to end in the state it starts. This allowed me to stop using AnimatedVectorDrawable.reset()
.
Section "Stale state" from this article helped me resolve the problem. Here is the important part of the section:
On older devices I found that their ‘state’ wasn’t being reset (to how it was defined in the VectorDrawable) on each loop. ... To fix this I added a zero length animation to set properties to their expected value at the start of each loop so that they’re ready to be animated e.g.:
<set>
<objectAnimator
android:propertyName="fillAlpha"
android:valueFrom="0"
android:valueTo="0"
android:duration="0" />
<objectAnimator
android:propertyName="fillAlpha"
android:valueFrom="0"
android:valueTo="1"
android:startOffset="1900"
android:duration="60"
android:interpolator="@android:interpolator/linear" />
</set>
This is the part that resets the animation to its initial state:
<objectAnimator
android:propertyName="fillAlpha"
android:valueFrom="0"
android:valueTo="0"
android:duration="0" />
valueFrom
and valueTo
are equal to valueFrom
in the second objectAnimator
.