Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 修复通用映像加载程序的警告:“0”;尝试初始化之前已初始化的ImageLoader。通用图像加载器“;_Android_Caching_Universal Image Loader - Fatal编程技术网

Android 修复通用映像加载程序的警告:“0”;尝试初始化之前已初始化的ImageLoader。通用图像加载器“;

Android 修复通用映像加载程序的警告:“0”;尝试初始化之前已初始化的ImageLoader。通用图像加载器“;,android,caching,universal-image-loader,Android,Caching,Universal Image Loader,每当我在应用程序中加载图像时,我的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. 我不明白为什么。这是我的密码: //I

每当我在应用程序中加载图像时,我的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

这是另一个有同样问题的人,但这对我没有帮助,因为我只在创建时初始化ImageLoader,只有一次。他一次又一次地初始化它。

我假设你在活动中有它

如果要将其放入其中,则必须在onDestroy上调用ImageLoader.destroy,如下所示:

protected void onDestroy() {
    ImageLoader.getInstance().destroy();
}
YourApplication extends Application {
    protected void onCreate() {
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
        .defaultDisplayImageOptions(defaultOptions)
        .denyCacheImageMultipleSizesInMemory()
        .build();
        ImageLoader.getInstance().init(config);
    }
}
您可以将初始化放在应用程序类中 大概是这样的:

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

我已经试过了,但是后来我得到了:“不能从ImageLoader类型静态引用非静态方法destroy()”哦,对了,我可以使用ImageLoader.getInstance.destroy(),我真傻,非常感谢你的帮助!