1

I am getting crash when animating views with camera preview.

Trace is following:

D/OpenGLRenderer: endAllActiveAnimators on 0x702565a400 (RippleDrawable) with handle 0x701d23cc60

D/AndroidRuntime: Shutting down VM

Fatal Exception: java.lang.IllegalStateException: The specified message queue synchronization barrier token has not been posted or has already been removed. at android.os.MessageQueue.removeSyncBarrier(MessageQueue.java:512) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1248) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6338) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874) at android.view.Choreographer.doCallbacks(Choreographer.java:686) at android.view.Choreographer.doFrame(Choreographer.java:621) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

I have implemented camera preview using Googles example and on top of the preview there is "auto-focus" oval which is animated visible/hidden using animate()method and alpha.

Niko
  • 8,093
  • 5
  • 49
  • 85
  • 1
    Possible duplicate of [Android Thread/Handler Error IllegalStateException: The specified message queue synchronization barrier token has not been posted](https://stackoverflow.com/questions/42554809/android-thread-handler-error-illegalstateexception-the-specified-message-queue) – AesSedai101 Nov 29 '17 at 13:41

1 Answers1

0

Turned out I wasn't forcing the thread to main when getting callback from the camera preview.

 private Handler mAutoFocusHandler = new Handler(Looper.getMainLooper());

Using this Handler to post Runnable where to animate the auto focus fixes the issue.

NOTE: Make sure to check that you are animating your own views on UI thread because View.animate() seemed to work when started from the camera background thread, but occasionally crashed the app.

Niko
  • 8,093
  • 5
  • 49
  • 85