I have looked around but have not found a solid solution to my problem. My application runs however when I naviagate around activities using bitmaps, I get the error, "Throwing OutofMemoryError "Failed to allocate 8294412 byte allocation with 690632 free bytes". I have snippets of my code below, used in two seperate activities. I have tried recycling the bitmaps, but that has not worked out well either.
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.dialogprofile, null);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
Uri myUri = Uri.parse(worldpopulationlist.get(position).getFilename1().toString());
File f = new File(worldpopulationlist.get(position).getFilename1().toString());
Bitmap myImg = BitmapFactory.decodeFile(myUri.getPath());
Matrix matrix = new Matrix();
Bitmap circleBitmap = Bitmap.createBitmap(myImg.getWidth(), myImg.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader (myImg, TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(myImg.getWidth()/2, myImg.getHeight()/2, myImg.getWidth()/2, paint);
int finalHeight, finalWidth;
holder.success.setImageBitmap(circleBitmap);
circleBitmap.recycle();
int width=800;
int height=700;
finalHeight = holder.event.getMeasuredHeight();
finalWidth = holder.event.getMeasuredWidth();
filenamee = worldpopulationlist.get(position).getFilename().toString();
Uri myUr = Uri.parse(worldpopulationlist.get(position).getFilename().toString());
File f1 = new File(worldpopulationlist.get(position).getFilename().toString());
Bitmap myImg1 = BitmapFactory.decodeFile(myUr.getPath());
myImg1=Bitmap.createScaledBitmap(myImg1, width, height, true);
Matrix matrix1 = new Matrix();
holder.event.setImageBitmap(myImg1);
}
});
return View;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.list_row, null);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
Uri myUri = Uri.parse(worldpopulationlist.get(position).getFilename().toString());
File f = new File(worldpopulationlist.get(position).getFilename().toString());
Bitmap myImg = BitmapFactory.decodeFile(myUri.getPath());
Matrix matrix = new Matrix();
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(),
matrix, true);
holder.flag.setImageBitmap(rotated);
}
});
return View;
}