Trying to cause the animation to play in a fragment of the activit. But I catch such a mistake:

android.util.AndroidRuntimeException: Animators may only be run on Looper threads 

Here is the fragment method that I call from activation:

  public void setConnect(){ ivOk.setPivotX(ivOk.getWidth()/2); ivOk.setPivotY(ivOk.getHeight() / 2); ObjectAnimator animator = ObjectAnimator.ofFloat(ivOk, "scale", 0, 1); animator.setDuration(350); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { ivOk.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animator.start(); } 
  • Most likely, you are trying to run an animation from another thread (not UI). Unfortunately you did not show the activation code where you call the fragment method. - mit
  • Yes, not from UI. Made a call inside runOnUIThread and it all worked, as I understand it - is this the only way? - Kirill Stoianov

1 answer 1

The error indicates that the animation you are running is not in Looper thread. The same as you did with runOnUIThread - it works, because the UI thread itself is a Looper thread. The second option is to use Handler .