I have an activity (activity1) which uses a decently large amount of bitmaps. I also have another activity which loads bitmaps (activity2). When running on some phones, I get an OOM error in activity2. I've tracked down the error to being caused by the layout in activity1. If I take out all of the bitamps in activity1, and replace them with just hex colors, then I do not get an OOM error in activity2.
So from this I'm assuming that the bitmaps I'm using in activity1 are not being removed from the heap when activity1's onPause or onDestroy methods are called. So far I've tried the answer from here but I still get my OOM error. Here's my onPause and onResume methods so far.
@Override
protected void onPause() {
mCache.onPause();
mContext = null;
mTimer.cancel();
mTimer = null;
unbindDrawables(findViewById(R.id.home_root));
System.gc();
super.onPause();
}
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
@Override
protected void onResume() {
super.onResume();
setContentView(R.layout.homescreen);
createButtons();
mCache.onResume();
performAnimation(false);
mTimer = new Countdown();
mTimer.start();
}
Any suggestions on how to fix this would be greatly appreciated! Thanks.