Problem with AnimationDrawable

All your problems with Audio, Video and Images.

Problem with AnimationDrawable

Postby » Mon Nov 22, 2010 10:48 pm


I have problems with AnimationDrawable which i use to animate a 'striped' gif file. In fact I have two animations that I want to use in one activity (and they must be used in the same activity). Both animation are build with 7 frames :

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  <animation-list xmlns:android=""
  3. android:id="@+id/analyse" android:oneshot="false">
  4.     <item android:drawable="@drawable/analyse_frame_0" android:duration="50" />
  5.     <item android:drawable="@drawable/analyse_frame_1" android:duration="50" />
  6.     <item android:drawable="@drawable/analyse_frame_2" android:duration="50" />
  7.     <item android:drawable="@drawable/analyse_frame_3" android:duration="50" />
  8.     <item android:drawable="@drawable/analyse_frame_4" android:duration="50" />
  9.     <item android:drawable="@drawable/analyse_frame_5" android:duration="50" />
  10.         <item android:drawable="@drawable/analyse_frame_6" android:duration="50" />
  11.  </animation-list>
Parsed in 0.004 seconds, using GeSHi

The second one is the same, just different files but also 7 frames.

In the onCrate method of my activity I start the first animation and launch a 15 second timer (the idea is that the first animation is playing when the timer ticks). I use the following code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onCreate(Bundle savedInstanceState) {
  2.                 super.onCreate(savedInstanceState);
  3.                 setContentView(R.layout.third);
  4.                 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  6.                 layout = (LinearLayout)findViewById(;
  7.                 analyseImage = (ImageView) findViewById(;
  8.                 analyseImage.setBackgroundResource(R.drawable.analyse_animation);
  10.                 analyseAnimation = (AnimationDrawable) analyseImage.getBackground();
  11.                 analyseAnimation.start();
  13.                 MyCount counter = new MyCount(15000,1000);
  14.                 counter.start();
  15.             }
Parsed in 0.037 seconds, using GeSHi

Unfortunately this does not work. However when the timer finishes I want to start a second animation and launch a seperate thread. And this works - when I start the animation in the 'onFinish' method of the timer, the animation starts properly:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onFinish() {                                                       
  2.                                 layout.setBackgroundResource(R.drawable.id_app4);
  4.                                 analyseImage .destroyDrawingCache();
  5.                                 analyseImage .setVisibility(View.GONE);
  7.                                 connectImage = (ImageView) findViewById(;
  8.                                 connectImage.setBackgroundResource(R.drawable.connect_animation);
  9.                                 connectAnimation = (AnimationDrawable) analyseImage.getBackground();
  10.                                 connectAnimation.start();                                  
  11.                                 startThread(connectTh,myConnector);                              
  12.                   }
Parsed in 0.034 seconds, using GeSHi

Unfortunately this does not work so good because it only works when I comment-out the first one - otherwise I get an Exception : 'OutOfMemoryError: bitmap size exceeds VM budget'. As you see I try to release some memory but this does not help. This is a crucial problem, since my application is working in a 'ring' of couple activities. So when I finish the last one it goes back to the first one - it is possible that the activity with animations will be called many times in the life-time of the whole app. So I need to release the memory from the second one as well.

So now here are my questions:
- why can't I start the first animation instantly after the activity starts and how to do this?
- How to release the memory from the animations?

Can anyone please help.

PS: I am working on Android 1.5
Junior Developer
Junior Developer
Posts: 22
Joined: Wed Jun 02, 2010 12:20 pm


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 7 guests