您的位置:首页 > 移动开发 > Android开发

Android 大量图片加载,使用什么加载库,避免OOM

2017-01-01 02:18 459 查看
我现在用的是Universal Image Loader,全局init以及配置config,但还是有OOM的问题出现

以下是这些配置的代码段

MyApplication.java
ImageLoaderConfiguration config = ImageLoaderConfigurationUtil.getCustomImageLoaderConfiguration(getApplicationContext());

ImageLoader.getInstance().init(config);


ImageLoaderConfigurationUtil.java
public class ImageLoaderConfigurationUtil {

public static ImageLoaderConfiguration getCustomImageLoaderConfiguration(Context context) {

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).memoryCacheExtraOptions(640, 640)

// default = device screen dimensions

.threadPoolSize(5)

// default

.threadPriority(Thread.MAX_PRIORITY - 1)

// default

.tasksProcessingOrder(QueueProcessingType.FIFO)

// default

// memoryCache

.memoryCache(new UsingFreqLimitedMemoryCache(16 * 1024 * 1024))

// memoryCacheSizePercentage

.memoryCacheSizePercentage(12)

// default

.diskCacheSize(50 * 1024 * 1024)

// diskCacheFileCount

.diskCacheFileCount(100)

// cacheFileNameGenerator

.diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default

.imageDownloader(new BaseImageDownloader(context)) // default

.imageDecoder(new BaseImageDecoder(true)) // default

// logs,delete it when release

.writeDebugLogs()

// build

.build();

return config;

}

}


DisplayImageOptionsUtil.java
public static DisplayImageOptions getDefaultOptions() {

DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.default_img).showImageForEmptyUri(R.drawable.default_img)

.showImageOnFail(R.drawable.default_img).resetViewBeforeLoading(false).cacheOnDisk(true).imageScaleType(ImageScaleType.IN_SAMPLE_INT)

.bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(0)).build();

return options;

}


现在的情况是这样,使用这个库在瀑布流里面加载图片,程序运行到一定时间后,开始出现OOM报错,程序虽然没有被FC,但是很多图片开始加载不出来,程序也明显的卡顿,想问一下大家,我这样的配置和使用方式是对的么,还有使用这个类库应该注意一些什么问题,要怎样及时回收掉不用的缓存?

又或者大家有什么好的异步图片加载类库推荐?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: