0

I'm using lottie animation inside my recyclerView.Here is a my source

     if (story.isRead)
            lottieAnimationView.setAnimation("story_archive_gray.json");
        else
            lottieAnimationView.setAnimation("story_archive_blue.json");



        final LinearLayout loadMoreContainer = v.findViewById(R.id.load_more_container);
        loadMoreContainer.setVisibility(story.isLastElement ? View.VISIBLE : View.GONE);

        rootView.setOnClickListener(view -> {

            lottieAnimationView.addAnimatorListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    SPLogger.logMassage("animationListener","onAnimationEnd");
                    animation.cancel();
                    //call activity
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    SPLogger.logMassage("animationListener","onAnimationCancel");

                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                    SPLogger.logMassage("animationListener","onAnimationRepeat");



                }
            });
            lottieAnimationView.playAnimation();

        });

I have one problem, sometimes animation does not finishing and onAnimationCancel has calling automatically .can anyone tell me a reason? I put my json files inside asset folders

BekaKK
  • 2,173
  • 6
  • 42
  • 80
  • 1
    Possible duplicate of [I want my RecyclerView to not recycle some items](https://stackoverflow.com/questions/36313079/i-want-my-recyclerview-to-not-recycle-some-items) – Martin Zeitler Apr 08 '19 at 23:53
  • ^ not an exact duplicate, but this appears to be likely the cause for the cancellation. – Martin Zeitler Apr 08 '19 at 23:55
  • I'm using custom view, not recyclerView @Martin Zeitler – BekaKK Apr 09 '19 at 00:12
  • do you have any experience in Lottie ? – BekaKK Apr 09 '19 at 00:12
  • I have, that's why I think that something higher up in the view-hierarchy might interfere and cause the animation to cancel. you could set a break-point within `onAnimationCancel()` and then check the call-stack, if one can see the origin. – Martin Zeitler Apr 09 '19 at 00:16
  • I can share my xml code,if you want @Martin Zeitler – BekaKK Apr 09 '19 at 00:18
  • this might make question more clear, because you refer to a `RecyclerView` ... – Martin Zeitler Apr 09 '19 at 00:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/191485/discussion-between-bekakk-and-martin-zeitler). – BekaKK Apr 09 '19 at 00:20
  • better try to set a break-point, to find out what is going on... I'm cooking right now. – Martin Zeitler Apr 09 '19 at 00:22
  • I tried it and As I said cancel method called @Martin Zeitler – BekaKK Apr 09 '19 at 00:29
  • it doesn't matter that it is being called, but what calls it. the call-stack is just alike a stack-trace, just not crashed with an exception... it only gets tricky when there are several threads involved. – Martin Zeitler Apr 09 '19 at 00:49
  • can you share a solution ? I did not understand your response correctly @Martin Zeitler – BekaKK Apr 09 '19 at 00:51
  • see this [tutorial](https://www.youtube.com/watch?v=nNKM4GLBpDg) or this [tutorial](https://www.youtube.com/watch?v=nBaL78HC0ls)... the window bottom-left is what I'm taking about. such issues don't have a default solution. one has to identify the actual problem, else one has little chance... things don't "just happen" (unless the OS is low on RAM). – Martin Zeitler Apr 09 '19 at 00:55
  • Dear Martin,I know how to use breakpoint in Android studio,but in this case I can't check a reason @Martin Zeitler – BekaKK Apr 09 '19 at 01:03
  • as stated [low ram](https://source.android.com/devices/tech/perf/low-ram) can have an effect on animations... there also is a profiler for RAM & GPU. also seen the [issue](https://github.com/airbnb/lottie-android/issues/1175) on GitHub, but they'll most likely also will label it "needs more information". – Martin Zeitler Apr 09 '19 at 01:22
  • It's my github issue :)))) – BekaKK Apr 09 '19 at 11:59

0 Answers0