I have a fragmentActivity that has a tabHost. Every Tab has inside a fragment which shows in the screen some ButtonTable. The following code is the ButtonTable:
public class ButtonTable extends Button {
private Paint paint= new Paint();
private Bitmap bmp= null;
private Table table= null;
int width= 0;
int height= 0;
boolean adjustmentForm= false;
private WeakReference<Bitmap> resizedBitmap;
public ButtonTable(Context context, Table table, int width, int height) {
super(context);
this.table=table;
this.width= width;
this.height= height;
setWidth(width);
setHeight(height);
setBitmapImage();
setBackgroundColor(INVISIBLE);
}
[...]
public void setBitmapImage(){
int resurce= R.drawable.rectangle6;
if(table.getTableType().equals("Circle6")){
resurce=R.drawable.circle6;
adjustmentForm= true;
}
if(table.getTableType().equals("Circle4")){
resurce= R.drawable.circle4;
adjustmentForm= true;
}
[...]
bmp = BitmapFactory.decodeResource(getResources(), resurce);
if(adjustmentForm){
bmp = Bitmap.createScaledBitmap(bmp, height, height, true);
}else{
bmp = Bitmap.createScaledBitmap(bmp,width, height, true);
}
resizedBitmap = new WeakReference<Bitmap>(bmp);
}
@Override
public void onDraw(Canvas canvas){
super.onDraw(canvas);
if(adjustmentForm){
canvas.drawBitmap(resizedBitmap.get(), ((width-height)/2), 0, null);
}else{
canvas.drawBitmap(resizedBitmap.get(), 0, 0, null);
}
}
}
If I move through the tabs for a while, after about 10/15 tab changes, the application stops because of a OutOfMemoryError. Why?