Search code examples
androiduniversal-image-loader

Universal Image Loader - Network is unreachable


I'm using Universal Image Loader library in order to load images from URLs, so now I'm testing some possible connection exceptions. In my specific situation I interrupted internet connection while it was loading images and the result is a series of errors messages (in the console, the app is doesn't crash) like "connect failed: ENETUNREACH (Network is unreachable)". How can I handle this?


Solution

  • You can configure UIL to show an image by default and on error. Have a look at displayOptions

    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.ic_stub) // resource or drawable
            .showImageForEmptyUri(R.drawable.ic_empty) // resource or drawable
            .showImageOnFail(R.drawable.ic_error) // resource or drawable
    

    Futher More in the loading listener you have a callback when loading fails here