I'm trying to implement an image gallery in android. The code based on http://www.mobisoftinfotech.com/blog/android/android-gallery-widget-example-and-tutorial/ and i've changed some details.
I'm using WeakReference and it seems, that when i've too many bitmaps, the garbage collector destroys my weakreferences. How can i handle this?
I get my bitmaps via this function:
public static WeakReference<Bitmap> getBitmap(String imageName, int width,
int height) {
String pathToImage = getPathToImage(imageName);
Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(pathToImage, options);
/*
* Calculate inSampleSize
*/
options.inSampleSize = calculateInSampleSize(options, width, height);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
WeakReference<Bitmap> scaledBitmap = new WeakReference<Bitmap>(
BitmapFactory.decodeFile(pathToImage, options));
return scaledBitmap;
}
And i've taken the Solution 320x480, so i think it is not this big...
When the gallery has more than 3 pictures, some of them aren't displayed.
Is the gallery-tutorial not that good? Are there other ways to implement this?
Thank you!