如何解决Glide Image Loading中的OutOfMemoryError。
引起:java.lang.OutOfMemoryError:无法分配5137932 字节分配为923120个空闲字节和901KB,直到OOMSent开启:2:54 没有被抓住 throwablejava.util.concurrent.ExecutionException: java.lang.OutOfMemoryError:无法分配5137932字节 在OOMat之前分配923120个空闲字节和901KB java.util.concurrent.FutureTask.report(FutureTask.java:94)在
的java.util.concurrent.FutureTask.get(FutureTask.java:164)com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor.afterExecute(FifoPriorityThreadPoolExecutor.java:96)在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1121)在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:588)在 java.lang.Thread.run(Thread.java:818)在 com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor $ DefaultThreadFactory $ 1.run(FifoPriorityThreadPoolExecutor.java:118)引起的 by:java.lang.OutOfMemoryError:无法分配5137932字节 在OOMat之前分配923120个空闲字节和901KB dalvik.system.VMRuntime.newNonMovableArray(Native Method)at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:882)在 android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:858)在 com.bumptech.glide.load.resource.bitmap.Downsampler.decodeStream(Downsampler.java:329)在 com.bumptech.glide.load.resource.bitmap.Downsampler.downsampleWithSize(Downsampler.java:220)在 com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:153)在 com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:50)在 com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:19)在 com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:39)在 com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:20)在 com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeBitmapWrapper(GifBitmapWrapperResourceDe
用于加载图片的Glide Image Loder代码
Glide.with(activity)
.load(items.get(position).getCharacterImageId(activity.getResources())) .placeholder(items.get(position).getColor(activity.getResources()))
.dontAnimate()
.thumbnail(0.7f)
.into(img_letter);
答案 0 :(得分:0)
android:largeHeap="true"
在清单文件中使用此行,例如:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
如果问题没有解决,请使用:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
mBitmapInsurance = BitmapFactory.decodeFile(mCurrentPhotoPath,options);
答案 1 :(得分:0)
您可以使用 android:largeHeap =&#34; true&#34; 来请求更大的堆大小,但这不适用于任何预装的Honeycomb设备。在2.3之前的设备上,您可以使用VMRuntime类,但这不适用于Gingerbread及更高版本。