I'm trying to set an image as a background to a view (PiePlot) but I'm getting OutOfMemory
exception.
Bg image size is 170kb.
I tried 5kb sample image for background and it works without exception.
I tried following :
@Override
protected void onDestroy() {
super.onDestroy();
unbindDrawables(mView);
System.gc();
}
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();
}
}
But this is useful if/when onDestroy()
called. But while starting the app, this won't work and hence app crashes.
I tried this also:
BitmapDrawable bitmapDrawable = (BitmapDrawable) ctx.getResources().getDrawable(R.drawable.bg2);
BitmapFactory.Options bitopt = new BitmapFactory.Options();
bitopt.inSampleSize = 10;
plot.setBackgroundImage(bitmapDrawable); //plot is PiePlot object
But same result i.e. app crashes.
Any help appreciated.