views:

43

answers:

1

Hi, I have 2 quiet big Animations each 50pics a 20kb Both defined as Animations .xml

One I let start from the beginning and the second after a button click.

//Start immediatly
  imgView.setBackgroundResource(R.layout.anim1);
                rocketAnimation = (AnimationDrawable) imgView.getBackground();

//Start after button click
  imgView.setBackgroundResource(R.layout.anim2);
                rocketAnimation = (AnimationDrawable) imgView.getBackground();

It works fine, till i hit the button and assign the second anim to my view

08-22 14:56:03.886: DEBUG/AndroidRuntime(1541): Shutting down VM
08-22 14:56:03.886: WARN/dalvikvm(1541): threadid=3: thread exiting with uncaught exception (group=0x4001da28)
08-22 14:56:03.886: ERROR/AndroidRuntime(1541): Uncaught handler: thread main exiting due to uncaught exception
08-22 14:56:04.096: ERROR/AndroidRuntime(1541): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-22 14:56:04.096: ERROR/AndroidRuntime(1541):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)

It looks definitly that each animation for itself is fine (i could even set anim2 at the autostart). but BOTH will exceed the memory.

Btw. on my Nexus One it works perfect. Where it fails is on G1 1.6 (even in Simulator).

So HOW would I release anim1 first before I assign anim2 ??

thx chris

A: 

Try to run

rocketAnimation.setCallback(null);

before you show anim2.

btw: N1 has more heap per app allowed (24mb) than the G1 (16mb). Samsung Galaxy S has even more (48MB). But via parameter you can also set a higher heap limit for the emulator; (unfortunately not for an unrooted phone though).

Mathias Lin
Hi, I tried right now... did not helped, still just crash :(as mentioned each one for it self work. so the mem for one of this anims is enough. but looks the last anim does not come released.
christian Muller
maybe the animation is simple too large for the device. you can calculate the memory that it eats up. see my reply on http://stackoverflow.com/questions/3238388/android-out-of-memory-exception-in-gallery/3238945#3238945 ... the file size of the images (ie. 20kB) doesn't matter, what matters is it's width and height. since it's all converted to bitmaps internally and thus relevant is the memory that these are using.
Mathias Lin
Thanks for now my app works fine on 2.2 (here the memory managment is much better)... will try your code also with 1.6 - 2.0for now it says in 2.2: 08-22 15:16:30.564: DEBUG/1(27859): debug.heap native: allocated 3.66MB of 3.70MB (0.03MB free) in [com.chris.myapp.mainactivity]08-22 15:16:30.564: DEBUG/1(27859): debug.memory: allocated: 2.00MB of 24.00MB (0.00MB free)
christian Muller