I know there are many questions, forums about OOM in Android in different situations, but I couldn't find a complete solution.
I have an activity where the user can scroll between many animations. Since only the animation should move when scrolling and at the beginning it must move without the user interaction, I used a ViewFlipper with the animations inside. As the image bellow schematically shows:
The problem is that on tablets and devices above 3.0 it throw OOM after flipping some animations and playing them. What I tried until now, in order to solve the problem:
- I scaled down the animation images using
BitmapFactory.Options
(I followed the tutorial Loading Large Bitmaps Efficiently tutorial). The only thing I didn't implement from the tutorial is the caching. - Since there are many animations, so many bitmaps, I loaded only 3 animation at a time (the current view, the one on the left and the one on the right), but adding and removing bitmaps has slowed down too much the app.
- I tried to make the garbage collector to release faster my images, by manually calling everything that could help:
setCallback(null)
,setImageDrawable(null)
,destroy()
,destroyDrawingCache()
(the last 2 for AdView). I even tryedrecycle()
(for Bitmaps), but it caused other exception
After the above changes there is some improvement, but I still receive OOM on an emulator Android 4.x WVGA854 or WVGA800 (after a longer period of time). But even when it doesn't trow OOM, the memory profiling shows 80% loading on the devices that were problematic to begin with. In addition the user experience is bad on all devices due to anim removal and addition.
I am starting to think is more an architecture/design problem. It might be an emulator problem? Do you now better memory profilers than the one in DDMS perspective?
I would be very grateful for any suggestion, I don't know what else to try:)