Its a known bug , its not due to large files. Since Android caches Drawables, it gets out of memory after using multiple images. But I found an alternative way to do this, skipping the default caching system for Android.
Soultion : Create a dedicated folder in Assets and move the images to the drawable folder in the assets and use the following function to get BitmapDrawable
public static Drawable getAssetImage(Context context, String filename) throws IOException { AssetManager assets = context.getResources().getAssets(); InputStream buffer = new BufferedInputStream((assets.open("drawable/" + filename + ".png"))); Bitmap bitmap = BitmapFactory.decodeStream(buffer); return new BitmapDrawable(context.getResources(), bitmap); }
Disclaimer: https://stackoverflow.com/posts/6116316/revisions
Also add the line below to the manifest file
android:largeHeap="true"
Quamber ali
source share