每当我在应用程序中加载图像时,我的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,只有一次。他一遍又一遍地初始化它。
答案 0 :(得分:2)
我假设您在活动中拥有它。
如果你要把它放在那里,你必须在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);
}
}