@Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

    // Get the animation container
    ImageView imageView = (ImageView) view.findViewById(R.id.animation_container);

    // Create the animation backend
    // In addition, we wrap it with an activity check. Tap the view to stop the animation to see
    // an inactivity toast message after 2 seconds.
    // In order to remove the inactivity check, just remove the wrapper method and set it to
    // the backend directly.
    AnimationBackend animationBackend =
        AnimationBackendUtils.wrapAnimationBackendWithInactivityCheck(
            getContext(),
            ExampleBitmapAnimationFactory.createColorBitmapAnimationBackend(
                SampleData.COLORS, 300, new NoOpCache()));

    // Create a new animated drawable, assign it to the image view and start the animation.
    final AnimatedDrawable2 animatedDrawable = new AnimatedDrawable2(animationBackend);

    imageView.setImageDrawable(animatedDrawable);

    imageView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (animatedDrawable.isRunning()) {
              animatedDrawable.stop();
            } else {
              animatedDrawable.start();
            }
          }
        });

    animatedDrawable.start();
  }
Fragment that creates a new {@link AnimatedDrawable2} and a custom bitmap animation backend that
cycles through colors and writes the frame number. Tap the view to start / stop the animation.

<p>When the animation is inactive for more than 2 seconds (no new frames drawn), a toast message
will be displayed.
samples/animation2/src/main/java/com/facebook/samples/animation2/bitmap/BitmapAnimationFragment.java