I have a children tale app - 18 pages, each page is an activity with a background image, short story and sound for every word(textView) in a story, and some animations.
I notice, when i go to next page, the memory is consumed;
it is also consumed when i go back to previous page(activity)! I get outOfMemory exception when the app reaches about 182MB usage - this can happen anytime.
How do I release images if the image is a background for RelativeLayout in every page ?
every time i navigate to next page, the previous is destroyed - should not the images it loads be released from memory as well?
public class Page8 extends Activity{
ImageView forward ;
ImageView backward ;
RelativeLayout main ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page8);
forward = (ImageView)findViewById(R.id.to_page_9);
backward = (ImageView)findViewById(R.id.to_page_7);
forward.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN) return false;
Intent intent = new Intent(Page8.this, Page9.class);
startActivity(intent);
return true;
}
});
backward.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN) return false;
Intent intent = new Intent(Page8.this, Page7.class);
startActivity(intent);
return true;
}
});
}
@Override
public void onStop(){
main = (RelativeLayout)findViewById(R.id.main) ;
main.releaseMemory()?;
}
}
I think you have HD images, you should optimize images and scale down them.