I've created simple test app with one activity. The activity contains frame animation. The total size of images in frame animation(riffle_forward_anim) is about 1MB. Here is the code I use to load animation:
public class MainScreen extends Activity {
/** Called when the activity is first created. */
private ImageView imgForward; private ImageView imgBack;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgForward = (ImageView) findViewById(R.id.imgForward);
imgForward.setBackgroundResource(R.anim.riffle_forward_anim);
}
@Override
public void onPause(){
super.onPause();
AnimationDrawable anim = (AnimationDrawable) imgForward.getBackground();
int count = anim.getNumberOfFrames();
for(int i=0;i<count;i++){
anim.getFrame(i).setCallback(null);
}
imgForward.getBackground().setCallback(null);
imgForward = null;
}
}
As you can see I try to release memory in onPause() method. Yes, I've read http://developer.android.com/resources/articles/avoiding-memory-leaks.html
Anyway crash occurs if I change protrait/landscape mode several times. I understand that I can handle orientation change and avoid crash but I need to release memory in my other app without orientation change. That is why I've created simple test app to understand how realisng memory works. Can anyone give me a hint on how to implement this?
Thanks