I am setting help screens images at 4 different places in my app. The activity code is the following-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help_list);
int screenType = getIntent().getIntExtra("screenName", 0);
ImageView imageView = (ImageView) findViewById(R.id.help_image);
switch (screenType) {
case 1:
imageView.setImageResource(R.drawable.help0);
break;
case 2:
imageView.setImageResource(R.drawable.help1);
break;
case 3:
imageView.setImageResource(R.drawable.help2);
break;
case 4:
imageView.setImageResource(R.drawable.help3);
break;
}
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
This code executes successfully on most of the devices, but on some devices (for e.g. Samsung), the app crashes with out of memory exception.
I've tried to recycle the Bitmap-
BitmapDrawable bitmapDrawable = ((BitmapDrawable) imageView.getDrawable());
if (bitmapDrawable != null) {
bitmapDrawable.getBitmap().recycle();
}
But the above code always gives null in the value of bitmapDrawable
. How can I fix this OutOfmemory exception?
P.S. The maximum size of the image drawables is 80kb