ObjectAnimator strange behaviour while trying to pause

85 views Asked by At

I have a few animated objects. I use a custom class to store their ImageViews and ObjectAnimators

And I have a method for pausing them. It looks pretty simple:

public void pause_animations(View view) {
    for (int i = 0; i < num_of_objects; i++) {
        objects[i].animator.pause();
    }
}

This method being called in 2 cases:

  1. As a button onClick.
  2. At some random time.

When I press a button and this code runs - everything works perfectly. All objects stop their moving. But in the second case, objects just freeze and teleport.

UPDATE. I have a touch listener. Every time user touches screen, a method try_to_pause(); runs.

private void try_to_pause() {
    if (number_of_touches % touches_to_pause == 0) {
        pause_animations(null);
    }
}
1

There are 1 answers

0
Xavier Rubio Jansana On

From the documentation of the Animator#pause() method, another reason may be that you started the animation from a different thread than main (emphasis is mine).

Pauses a running animation. This method should only be called on the same thread on which the animation was started.