Animation and OutOfMemoryError

All your problems with Audio, Video and Images.

Animation and OutOfMemoryError

Postby srd.pl » Wed Nov 24, 2010 1:38 pm

Ok I have posted a similar topic but there was no response and now the situation has changed a little bit.

I have an app where in one of the activities I launch 2 animation. I load the first one at the start of an activity (in onWindowFocusChanged method) and then after a timer finishes i changed it to the other one. Unfortunately when for example I exit the app and open it again I get an out of memory exception. This also happens when I I want to enter the same activity in my app without exiting. I have put some code that I though would free the memory but it doesn't work. How can I free the memory?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.   @Override
  2. public void onWindowFocusChanged(boolean hasFocus) {
  3.                 super.onWindowFocusChanged(hasFocus);
  4.                 if ( this.firstLaunch)
  5.                 {
  6.                           analyseAnimation.start();
  7.                            firstLaunch = false;
  8.                 }
  9.                 if ( !hasFocus)
  10.                 {
  11.                                 listeningAnimation.setCallback(null);                  
  12.                                 connectAnimation.setCallback(null);
  13.                                 animationImage.setBackgroundDrawable(null);
  14.                 }
  15.             }
  16. @Override
  17.         public void onDestroy()
  18.             {
  19.                 super.onDestroy();
  20.                 layout.setBackgroundDrawable(null);
  21.                 listeningAnimation.setCallback(null);                  
  22.                 connectAnimation.setCallback(null);
  23.                 animationImage.setBackgroundDrawable(null);
  24.             }
  25.            
  26.             @Override
  27.         public void onPause()
  28.             {
  29.                 super.onPause();
  30.                 layout.setBackgroundDrawable(null);
  31.                 listeningAnimation.setCallback(null);                  
  32.                 connectAnimation.setCallback(null);
  33.                 animationImage.setBackgroundDrawable(null);
  34.             }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


The ImageView and AnimationDrawable variables are non-static fields of the activity class. I am working on android 1.5

Does any one know how to free the memory properly in this case??
srd.pl
Junior Developer
Junior Developer
 
Posts: 22
Joined: Wed Jun 02, 2010 12:20 pm

Top

Re: Animation and OutOfMemoryError

Postby Schermvlieger » Thu Nov 25, 2010 9:44 am

I use to call finalize() on memory heavy objects when I don't need them anymore.
Schermvlieger
Senior Developer
Senior Developer
 
Posts: 159
Joined: Fri Feb 26, 2010 1:37 pm

Re: Animation and OutOfMemoryError

Postby srd.pl » Thu Nov 25, 2010 9:56 am

Thanks Schermvlieger, but can you tell a little bit more? Neither the ImageView or AnimationDrawable classes have such a method.
srd.pl
Junior Developer
Junior Developer
 
Posts: 22
Joined: Wed Jun 02, 2010 12:20 pm

Re: Animation and OutOfMemoryError

Postby srd.pl » Thu Nov 25, 2010 11:37 am

Ok it still needs some more testing but it looks like I have solved the problem by creating the animation with manually adding Bitmaps as frames, and then calling recycle() on them. And I can now run the 2 animations with full frame and size. It is a less elegant approach and more 'hard-coded' but at least it seems to be working. Really strange, annoying and stupid that the approach google suggest on android developer site creates such an error and you can't find any answer and some other approach which needs to be figured out on your own works....
srd.pl
Junior Developer
Junior Developer
 
Posts: 22
Joined: Wed Jun 02, 2010 12:20 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 28 guests