diff --git a/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SpineView.java b/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SpineView.java index 07947d041..1bf17ad8c 100644 --- a/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SpineView.java +++ b/spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SpineView.java @@ -181,6 +181,8 @@ public class SpineView extends View implements Choreographer.FrameCallback { private Alignment alignment = Alignment.CENTER; private ContentMode contentMode = ContentMode.FIT; + private boolean isAttached = false; + /** Constructs a new {@link SpineView}. * * After initialization is complete, the provided {@code SpineController} is invoked as per the {@link SpineController} @@ -208,6 +210,18 @@ public class SpineView extends View implements Choreographer.FrameCallback { // Set properties by view id } + @Override + protected void onAttachedToWindow () { + super.onAttachedToWindow(); + isAttached = true; + } + + @Override + protected void onDetachedFromWindow () { + super.onDetachedFromWindow(); + isAttached = false; + } + /** Constructs a new {@link SpineView} from files in your app assets. The {@code atlasFileName} specifies the `.atlas` file to * be loaded for the images used to render the skeleton. The {@code skeletonFileName} specifies either a Skeleton `.json` or * `.skel` file containing the skeleton data. @@ -407,10 +421,9 @@ public class SpineView extends View implements Choreographer.FrameCallback { controller.setCoordinateTransform(x + offsetX / scaleX, y + offsetY / scaleY, scaleX, scaleY); } - // Choreographer.FrameCallback - @Override public void doFrame (long frameTimeNanos) { + if (!isAttached) return; if (lastTime != 0) delta = (frameTimeNanos - lastTime) / 1e9f; lastTime = frameTimeNanos; invalidate();