gpt4 book ai didi

android - 修复 Universal Image Loader : "Try to initialize ImageLoader which had already been initialized before. Universal image loader" 的警告

转载 作者:行者123 更新时间:2023-11-29 00:12:04 26 4
gpt4 key购买 nike

每当我在我的应用程序中加载图像时,我的 logcat 都会给我这条消息。

04-09 19:09:59.241: W/ImageLoader(276): 
Try to initialize ImageLoader which had already been initialized before.
To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.

我不明白为什么。这是我的代码:

//If save on disk setting is false, do not save on disk. else, save on disk.
if (dataReturned =="false"){
defaultOptions = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(false)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
}else{
defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisc(true)
.cacheInMemory(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
}
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.denyCacheImageMultipleSizesInMemory()
.build();
ImageLoader.getInstance().init(config); // Do it on Application start

这是别人遇到同样的问题,但对我没有帮助Fix a warning of ImageLoader : "Try to initialize ImageLoader which had already been initialized before"因为我只初始化 ImageLoader onCreate,所以只有一次。而他一遍又一遍地初始化。

最佳答案

我假设您在 Activity 中有它。

如果你打算把它放在那里,你必须像这样在 onDestroy 上调用 ImageLoader.destroy:

protected void onDestroy() {
ImageLoader.getInstance().destroy();
}

您可以将初始化放在应用程序类中 http://developer.android.com/reference/android/app/Application.html像这样:

YourApplication extends Application {
protected void onCreate() {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.denyCacheImageMultipleSizesInMemory()
.build();
ImageLoader.getInstance().init(config);
}
}

关于android - 修复 Universal Image Loader : "Try to initialize ImageLoader which had already been initialized before. Universal image loader" 的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29545107/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com