Java – images are not cached locally (using the general image loader) – slow image loading time
Problem Description:
Image loading is very slow... I thought using the "universal image loader" to cache images on the device would make them just seem to scroll to the view if you've seen it (or at least close) But – when you drag up / down, there are no images in the image, and then after 3-5 seconds, the images begin to pop up (just like downloading them again)
I'm changing the visibility of thumbnail boxes, but it's perfect - they don't seem to change - they just scroll into the view without flashing or anything (but the image will not appear for a few more seconds)
I've deleted my PHP script by scrolling... When I roll back to the previous point, the image doesn't display - let me assume it loads from my PHP script every time
But according to the docs: "using freqlimitedmemorycache (the most commonly used bitmap is deleted when the cache size limit is exceeded) – used by default"
Details:
In my articleentryadapter JS I have:
@Override public View getView(final int position,final View convertView,final ViewGroup parent) { // We need to get the best view (re-used if possible) and then // retrieve its corresponding ViewHolder,which optimizes lookup efficiency final View view = getWorkingView(convertView); final ViewHolder viewHolder = getViewHolder(view); final Article article = getItem(position); // Set the title viewHolder.titleView.setText(article.title); //Set the subtitle (subhead) or description if(article.subtitle != null) { viewHolder.subTitleView.setText(article.subtitle); } else if(article.description != null) { viewHolder.subTitleView.setText(article.description); } ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.displayImage("",viewHolder.thumbView); //clears prevIoUs one if(article.filepath != null && article.filepath.length() != 0) { imageLoader.displayImage( "http://img.sltdb.com/processes/resize.PHP?image=" + article.filepath + "&size=100&quality=70",viewHolder.thumbView ); viewHolder.thumbView.setVisibility(View.VISIBLE); } else { viewHolder.thumbView.setVisibility(View.GONE); } return view; }
As long as the image is incorrect - it's not often, but sometimes when I scroll, I see the same image 2. When I read the article, they are not completely related (i.e. there is no chance to actually use the same image), so - I roll it away and come back, it's no longer an incorrect image
Note: I'm new to Java / Android – you may have noticed
More codes per comment request:
private View getWorkingView(final View convertView) { // The workingView is basically just the convertView re-used if possible // or inflated new if not possible View workingView = null; if(null == convertView) { final Context context = getContext(); final LayoutInflater inflater = (LayoutInflater)context.getSy@R_419_2354@Service (Context.LAYOUT_INFLATER_SERVICE); workingView = inflater.inflate(articleItemLayoutResource,null); } else { workingView = convertView; } return workingView; }
Update: my inventory files are:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
But I found the cache folder completely empty:
mnt -sdcard -Android -data -com.mysite.news -cache -uil-images
Solution
I have a problem with images in the list view Maybe this answer will correct your wrong image problem
I just downloaded the sample project using universal image loader and showed the same behavior you described
So far, several comments can't see the source code clearly
public static final int DEFAULT_THREAD_POOL_SIZE = 3; public static final int DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY - 1; public static final int DEFAULT_MEMORY_CACHE_SIZE = 2 * 1024 * 1024; // bytes
This means that three threads will download up to 2MB of images at any time How big is the picture you downloaded? Do you still cache to disk? If so, it will be slow
To configure some basic options in imageloader, you need to pass in displayimage:
DisplayImageOptions options = new DisplayImageOptions.Builder() .showStubImage(R.drawable.stub_image) .cacheInMemory() .cacheOnDisc() .build();
I also want you to try these options:
ImageLoaderConfiguration imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this) .enableLogging() .memoryCacheSize(41943040) .discCacheSize(104857600) .threadPoolSize(10) .build(); imageLoader = ImageLoader.getInstance(); imageLoader.init(imageLoaderConfiguration);
Through my test, the image is on disk, but the loading is still very slow
After extensive testing, the main problem I identified was that the universal image loader was just slow Specifically, imageloader and loadanddisplayimagetask are keeping works I (quickly) rewritten the loadanddisplayimagetask as an asynctask, which immediately performs better You can download the forked version of the code on GitHub
Universal Image Loader with AsyncTasks