Search code examples
androidout-of-memoryanimationdrawable

Out of memory issues with AnimationDrawable


I need to show frame-animation on an ImageView. I am using AnimationDrawable to play the animation on some click event. Its working fine if I show single animation. But based on the button clicked I need to show three different animations.When I'm playing the second animation OutOfMemoryError is thrown. As suggested by some other post on the same issue I am recycling the bitmaps after the animation is over. But in app, on clicking the same button again I need to show the same Animation. But as I am trying to use recycled bitmaps its not working..is there any work around for this problem???


Solution

  • Following form comments: You load too much data.

    Assuming ARGB images:

    width x height x images x colordept = bytes used
    450 * 420 * 20 * 4 = 30240000.
    

    That's 14 MiB when you load the full animation. This is guaranteed to blow up your ram.