My main activity is composed of a gallery which loads in cache 100mb photos and that's ok since they are more than 30 bitmaps. I got the problem when clicking on one of the images: i'm passing an id in the Intent and getting the bitmap from Parse to load the Photo bigger when it is clicked.
public class ImageFragment extends FragmentActivity {
ImageView imageView;
Bitmap imageBitmap;
public void onCreate(Bundle savedInstanceState) {
final Context mContext = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_image);
final View v = new View(this.getApplicationContext());
String objectID = getIntent().getExtras().getString("objectID");
final ImageView imageView= (ImageView) findViewById(R.id.image_view_fragment);
ParseQuery<ParseObject> queryFoto = new ParseQuery<ParseObject>("Photo");
queryFoto.whereEqualTo("objectId", objectID);
queryFoto.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
ParseFile f = objects.get(0).getParseFile("photo");
f.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
imageBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
//BitmapUtil.scala is a function
imageView.setImageBitmap(BitmapUtil.scala(imageBitmap));
}
});
} else {
//this is a fuction to check error
check(e.getCode(), v, e.getMessage());
}
}
});
}
and this is the scala function
public static Bitmap scala(Bitmap imageBitmap){
int w=imageBitmap.getWidth();
int h=imageBitmap.getHeight();
int maxsize=GL10.GL_MAX_TEXTURE_SIZE;
System.out.println("w="+w+" h="+h+" maxsize="+maxsize);
Bitmap scaledBitmap=imageBitmap;
if (imageBitmap.getWidth() > GL10.GL_MAX_TEXTURE_SIZE ) {
System.out.println("1");
float aspect_ratio = ((float) imageBitmap.getWidth()) / ((float) imageBitmap.getHeight());
int wout=maxsize-1;
int hout= (int) (wout/aspect_ratio);
System.out.println("aspect_ratio"+aspect_ratio+" wout"+wout+" hout"+hout);
scaledBitmap = Bitmap.createScaledBitmap(imageBitmap,(int)wout-1, (int)hout-1,false);
}
if(imageBitmap.getHeight()>GL10.GL_MAX_TEXTURE_SIZE){
System.out.println("2");
float aspect_ratio = ((float) imageBitmap.getWidth()) / ((float) imageBitmap.getHeight());
int hout=maxsize-1;
int wout= (int) (aspect_ratio*hout);
System.out.println("aspect_ratio"+aspect_ratio+" wout"+wout+" hout"+hout);
scaledBitmap = Bitmap.createScaledBitmap(imageBitmap,(int)wout-1, (int)hout-1,false);
return scaledBitmap;
}
return scaledBitmap;
}
So the problem is that it allocates 60mb just for this activity, and it doesn't deallocate when back is pressed. The photo is about 1Mb and i've tried to scale it but it isn't working.