I'm writing an app now which uses four main buttons that take up most of the screen. Each one has three animations: a 12 frame introductory animation, a 33 frame looping animation, and an animation that closes based on the current frame the loop was clicked.
Images around around 250 250 to 450 250 in height. Loading all of these as the app loads has turned out to not only cause slow initial loading, but also has resulted in Out of Memory Exceptions on devices with smaller available memory.
The problem is that when I try to load the animations without preloading them, it skips and hangs for a second before loading it. Also, I noticed that even while just running active animations when they are needed per click listeners, memory usage seems to go from between 20mb to 40mb heap size.
I'm not really doing anything weird implementing them. I use a standard
AnimationDrawable animation = (AnimationDrawable)getResources().getDrawable(R.drawable.blah);
imageView.setImageDrawable(animation);
animation start;
But then loading individual animations as needed without preloading makes a slight delay. Is there a way to pre preload them (if that makes any sense) or do something else in terms of how I'm implementing them in code? I'm currently working on chopping the animations into different parts so the only frames changing are the actual parts of the object that are animated.
Other than that, how else can I deal with AnimationDrawable and memory? It seems like Animation is so fundamental to Android, there must be better, professional ways of handling animated resources so they don't break the memory bank and are still fluid. Please let me know I'm doing this the stupid way. Should I be using a different animation class, or perhaps manually assigning changed to an animated view based on a timer so I'm loading one at a time?
I guess this is kind of a messy question - it just seems like there's got to be a standard way of handling this kind of problem. Less frames? Different format images? (jpg and png were the same)