2

I am working on some old android code where the code looks something like this:

public void TestMethod() {
    // handler posting on main thread
    handler.post(() -> {
        //Invokes method();    
    });

    animation.addListener(new AnimatatorListenerAdapter(){
         @Override
         public void onAnimationEnd() {
             // Do some stuff;
         }
    });
    animation.start();
} 

As per my understanding, the animation life cycle callbacks always execute on UI thread. Since method() is posted first on message queue therefore it should be executed before onAnimationEnd(), but some times (3/10 times) onAnimationEnd executes before method(). Therefore now I am confused about android animation ( Surely I am missing something).

Questions:

  • What should be the ideal flow in this code?

  • Between method() and onAnimationEnd(), which one will be executed first and why?

  • How android animation executes on UI thread without blocking other messages and runnable in the message queue of UI Thread?

imvishi
  • 233
  • 4
  • 18

0 Answers0