airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
34.98k stars 5.4k forks source link

onStop() of previous activity is called only after 10 seconds #641

Closed mateusgrb closed 6 years ago

mateusgrb commented 6 years ago

I have an Activity A that starts an activity B, which contains a fragment, which in turn has a fullscreen LottieAnimationView. I display that animation while data is being fetched from the network.

I've noticed that the onStop() method from Activity A takes about 10 seconds to be called after B is started. In contrast, when we navigate from A to other activities, the method is called right after(< 1 second). This delayed calls makes the animation give a quick freeze, which is something we want to avoid.

Also, if I comment out the line that starts the animation in the fragment(lottieAnimationView.resumeAnimation();), onStop() is quickly called(~1 second). This makes me think that the long delay in calling that method is being caused by Lottie.

I've also replaced my json file with this one from lottie files: https://www.lottiefiles.com/1385-lets-go. The long delay persists.

I'm using 2.3.1 but I've already tried it on 2.5.0 and the behavior is the same.

Does that ring any bell already or do you need more info to investigate that?

Thanks in advance.

gpeal commented 6 years ago

@mateusgrb This is very bizarre... Can you create a minimal project that repros this? We haven't experienced anything like this before.

gpeal commented 6 years ago

As a test, try calling useHardwareAcceleration

geeksammao commented 6 years ago

@mateusgrb I have experienced this before on an Android 7.0 device, but I didn't use Lottie and use a infinite view animation instead.I solved the problem by stopping the animation in onPause and resuming it in onResume.I guess Android 7.0 changed some behavior about animation.

mateusgrb commented 6 years ago

@gpeal Here's a minimal project that reproduces the issue. I'm running on a Nexus 6P Android 8.1.0

Note that LottieManager is a class that loads the composition on startup, so that it's potentially already loaded when requested. That's the strategy I'm using on my main app.

The animation used here is https://www.lottiefiles.com/1505-beauty

LottieIssue.zip

videotogif_2018 03 01_10 31 20

gpeal commented 6 years ago

@mateusgrb Thanks for the sample! I figured it out. Your animation actually runs significantly worse with hardware acceleration turned on. As a result, every frame was taking more than 16ms which caused Choreographer to post a vsync message at the front of the queue and prevented the onStop message from ever getting to the front until the animation stopped or a frame finished in time for the message queue to clear.

Simply turning off hardware acceleration caused your animation to become performant enough to run at 60fps.

Thanks for the fun challenge 😝