Since that loading large bitmaps to show on a device screen in android(the correct way) is not a trivial task, I took a look on some tutorials on how to effectively make it. I'm already aware that you need to do the following in order to make a memory efficient image loader method:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; //do that to avoid loading all the information on the heap to decode
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
Acoording to the google tutorial you should make a sampled sized image, until this point I understand, you should make a method like this:
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
And Finally you call the method like this:
imageView.setImageBitmap(decodeSampledBitmapFromResource(getResources(), drawable.big_image, 200, 200));
And here is where my doubt lies: How to know the best size values according to the devices's screen size/resolution ? Is there any method that I can embed on my code which returns the optimal screen resolution to load an image without the pixelated effect and yet not too big that would blow up the VM heap ? This is one of the biggest challenges I'm facing on my project right now. I searched this link(and others I don't remember) but I couldn't find the answer I'm looking for.