Volley - NetworkImageView sometimes not showing error image?

So, I decided to try the new Volley library , as shown on Google IO 2013 .

I tried this using a simple NetworkImageView solution to show multiple images on a GridView .

It works well and shows images, but if I let it download images and then turn off WiFi during boot, it does not show an error, as if it was still loading. Not only that, but if I restore the connection, it will not resume the download.

Why is this happening, and how can I fix it? Maybe this is actually a mistake?

Here is my sample code if someone wants to try ( BitmapCacheLru code here ):

 public class MainActivity extends Activity { private static final int COLUMNS_COUNT = 4; private RequestQueue _requestQueue; private ImageLoader _imageLoader; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); _requestQueue=Volley.newRequestQueue(this); _imageLoader=new ImageLoader(_requestQueue, new BitmapLruCache()); final GridView gridView = new GridView(this); gridView.setNumColumns(COLUMNS_COUNT); final int screenWidth = getResources().getDisplayMetrics().widthPixels; gridView.setAdapter(new BaseAdapter() { @Override public View getView(final int position, final View convertView, final ViewGroup parent) { NetworkImageView rootView = (NetworkImageView) convertView; if (rootView == null) { rootView = new NetworkImageView(MainActivity.this); rootView.setLayoutParams(new AbsListView.LayoutParams(screenWidth / COLUMNS_COUNT, screenWidth / COLUMNS_COUNT)); rootView.setScaleType(ScaleType.CENTER_CROP); rootView.setDefaultImageResId(android.R.drawable.sym_def_app_icon); rootView.setErrorImageResId(android.R.drawable.ic_dialog_alert); } final String url = getItem(position); rootView.setImageUrl(url, _imageLoader); return rootView; } @Override public long getItemId(final int position) { return 0; } @Override public String getItem(final int position) { return Images.imageThumbUrls[position]; } @Override public int getCount() { return Images.imageThumbUrls.length; } }); setContentView(gridView); } @Override protected void onStop() { _requestQueue.cancelAll(this); super.onStop(); } } 

PS If you want to see the NetworkImageView code, I think it is available here .

+3
source share
1 answer

I think the problem is that volleyball will not help you reload the image.

A quick scan shows that NetworkImageView only loads data when the onLayout method is called, and the loadImageIfNecessary method will redirect the network request if necessary.

If there is no Internet connection, an error callback will be called, and after the Internet connects itself, no action will be taken.

However, since you have NetworkImage in the list when you scroll through the list, I assume that you will use the cell view again and call setImageURL again. If an internet connection is available, the image will be downloaded automatically. Alternatively, after connecting to the Internet, you can update the list view and upload the image automatically.

+5
source

Source: https://habr.com/ru/post/952988/


All Articles