Asynchronous download for Android (Asynchttpclient and Volley)

Source: Internet
Author: User

Made a small case to get the picture from the network and load it into Viewpager just started using asynchttpclient for data download and encapsulated a method inside a class class is the use of async I want to get the result of Async's network request by the return value of the method of this class of encapsulation. How can the results of network requests not get the result of the Web request and then the debugging process found that the network request is actually requested, but in the return of the method is not returned, so only to reflect the reason of the thread I checked the back again. Async's Onsuccess method is that the main thread handles only a certain understanding of the threads and has no coding experience so it abandons async

And then study the use of volley, just started to use for the loop load Imagerequest to fetch the network picture one of the package into the map and then the map into a list and then the list returned to the same as async real new, so I studied again

Finally, use Imageloader and use LRUCache to cache the picture.


for (int i=0;i<urls.length;i++) {
ImageView image = New ImageView (getactivity ());
Image.setscaletype (ImageView.ScaleType.FIT_XY);

Image.setonclicklistener (New Myclick (i));
Imageloader Imageloader = new Imageloader (Requestqueue,bitmapcache);
Imagelistener listener = Imageloader.getimagelistener (image, R.drawable.icon_default, r.drawable.image10);
Imageloader.get (Urls[i], listener);
Views.add (image);
}

Asynchronous download for Android (Asynchttpclient and Volley)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.