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 .
source share