I have been using viewPager to load images: it workers perfectly for two images, however when I increases the number of images it crashed. I have compressed the image sizes but this did not solve the problem. According to some questions which are similar on StackOverflow I have also used Recycle but this as well did not solve the problem
any other way to increase memory management ?
thanks
Have you used the sample size to scale them? Try creating the bitmaps with this, so it loads only the size bitmap required rather than the full size into memory.
public int calculateInSampleSize(BitmapFactory.Options options) {
DisplayMetrics displayMetrics = cxt.getResources().getDisplayMetrics();
int reqWidth = displayMetrics.widthPixels;
final int height = options.outHeight;
final int width = options.outWidth;
double devCal2 = (height*1000)/width;
int reqHeight = (int) ((devCal2/1000)*reqWidth);
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
public Bitmap createBitmap(){
BitmapFactory.Options options2 = new BitmapFactory.Options();
options2.inJustDecodeBounds = true;
options2.inDither=true;
BitmapFactory.decodeFile(cxt.getExternalFilesDir(filepath) +"/companylogo.png",options2);
options2.inSampleSize = calculateInSampleSize(options2);//=32
options2.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(cxt.getExternalFilesDir(filepath) +"/companylogo.png",options2);
}
For reference please check http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
I also read that using weak reference is a good idea for images, maybe this will help http://eclipsesource.com/blogs/2012/07/31/loading-caching-and-displaying-images-in-android-part-1/