Animation at the beginning of activity jumps

I am working on animating custom Views for my Android app. I have accomplished this via Property Animations and calling invalidate() on the View in the onAnimationUpdate() callback, as per

Depending on what property or object you are animating, you might need to call the invalidate() method on a View to force the screen to redraw itself with the updated animated values. You do this in the onAnimationUpdate() callback.

  • How can I execute something just once per application start?
  • First time user guide-through Android library
  • Android ViewGroup crash: Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
  • making a GSON request using volley
  • Unhandled event loop exception in plugin org.eclipse.ui
  • How to make EditText smaller than default?
  • My problem is that when these animations are run at the beginning of a newly launched Activity, they skip frames at the beginning, causing them to jump very noticeably. I have tried both:

    1. Starting the animation immediately from the Activity’s onCreate() method
    2. Starting the animation upon the OnGlobalLayout() callback using the ViewTreeObserver of the Activity’s root view.

    I did the latter since I thought maybe the animation was invoked before the layout had been finalized, but the result is the same.

    With logs, I determined that the onAnimationUpdate() callback is called consistently throughout the animation (that is, every 10-20 ms or so, from start to end). onAnimationUpdate() simply calls invalidate(), which should force the View to redraw itself, ideally immediately (but the documentation only claims this happens “at some point in the future”). That seems to be precisely the problem: onDraw() is only called once or twice at the very start before not being called for about 250 ms. After this, it resumes being called every 10-20 ms, as it should have the whole time. But that block of time causes very noticeable lag in the animation.

    To be clear, this problem only happens at the beginning of the Activity. If I simply set a 300 ms delay before starting the animation, it runs smoothly all the way through. But I don’t like that solution, since it’s hacky. It seems the problem is that onDraw() is not called immediately upon invalidate() near the beginning of the Activity. But, I can’t figure out why this is, what’s blocking onDraw(), or how to fix it at all.

    I found only this StackOverFlow thread: Animation at the beginning of activity skips frames where the poster has the identical problem. The basic code is there and the videos make the problem clear. I can post my code too, but I think that the fact that the problem appears in the most basic test app shows that there’s something else going on.

    Related posts:

    Android: get unique ID of notification
    android mms download mms content through mms url
    Android: custom view layout for SectionIndexer and disabling SectionIndexer on the fly
    AppCompat Toolbar: Change Overflow Icon Color in ActionMode
    NullPointerException from getExtras()
    GridView.setOnItemClickListener is not working
  • How could Intent be null in onHandleIntent()?
  • how to use Digest authentication in android?
  • * vs ** vs *** in Proguard?
  • Tablet Screen Orientation Change - No View found for id for Fragment
  • Bluetooth socket freeze phone
  • Does bugsense crash handler need to be called in each activities of an Android application?
  • 2 Solutions collect form web for “Animation at the beginning of activity jumps”

    Since there are no codes attached, I’m assuming you have some transition animation to the activity. If this is the case, it might cause the problem.Since there are two animations running simultaneously. Disable the transition and give it try.

    getActivity().overridePendingTransition(0, 0); 

    It sounds like your draw loop UI thread is getting starved.

    I’d use traceview to be sure that there aren’t any methods blocking your draw calls.

    This should help you determine what’s being invoked instead of the onDraw method.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.