From e48ef2a3efedebdcc351b60d2f3c35c987811938 Mon Sep 17 00:00:00 2001 From: George Mount Date: Fri, 31 Oct 2014 14:23:34 -0700 Subject: [PATCH] Cancel animation when target changes. Bug 18201083 Change-Id: I2ea15063b18881c4b31ae6cdc287649dbc4a61f7 --- core/java/android/animation/ObjectAnimator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/java/android/animation/ObjectAnimator.java b/core/java/android/animation/ObjectAnimator.java index 500634ceab837..59daaab44a841 100644 --- a/core/java/android/animation/ObjectAnimator.java +++ b/core/java/android/animation/ObjectAnimator.java @@ -885,7 +885,8 @@ public final class ObjectAnimator extends ValueAnimator { } /** - * Sets the target object whose property will be animated by this animation + * Sets the target object whose property will be animated by this animation. If the + * animator has been started, it will be canceled. * * @param target The object being animated */ @@ -893,6 +894,9 @@ public final class ObjectAnimator extends ValueAnimator { public void setTarget(@Nullable Object target) { final Object oldTarget = getTarget(); if (oldTarget != target) { + if (isStarted()) { + cancel(); + } mTarget = target == null ? null : new WeakReference(target); // New target should cause re-initialization prior to starting mInitialized = false;