Network request framework --- Volley, request framework --- volley

Source: Internet
Author: User

Network request framework --- Volley, request framework --- volley

Last year's Google I/O conference brought a network request framework for android Developers called Volley. Volley's mission was to make Android's network request faster and more robust, and its network communication implementation was based on HttpURLConnection. I sorted out two network request tool classes a few days ago, and it was okay to cope with the development needs of daily work. I encapsulated them on the basis of HttpURLConnection and HttpClient, respectively, this ensures that the API is concise and friendly. If you are interested, you can go back to the page and find the source code on Github.AndroidHttpUtil. Volley implements its network request function based on jdk's native network request class and BlockingQueue. The following describes the benefits of Volley for programming.

Procedure

  1. Git clone https://android.googlesource.com/platform/frameworks/volley

  2. Import the project and then use the export Jar package. We recommend that you export the package with the source code to facilitate viewing the source code.

Image loading


At the same time, Volley also provides developers with an ImageView, NetworkImageView, that directly loads network URLs, which is more convenient to use.

HTTP Request

Volley supports all eight Http request methods and callback for successful and failed requests. You can also set the timeout time, number of reconnections after failure, url cache, and Tag for the Request to interrupt the Request. If the request is successful, the String, JsonObject, and custom bean can be received. If the request fails, VolleyError has many sub-classes, which makes it easy to troubleshoot network request failures.

GET request implementation

If you need to add Request parameters, you can repeat the getParams () method in the Request and return a Map set containing the Request parameters. At the same time, if the request thread is interrupted is also very simple, you can directly use cancel through the request reference, you can also use

RequestQueue. cancelAll (TAG_REQUEST) is interrupted Based on the tag bound to the request. This avoids unnecessary background threads running when the page ends. Volley also supports priority and sorting of network requests.

Conclusion: It took me half a day to study Volley and found two scenarios for trial use. First, network image loading, and second, network requests return data in json format. However, its advantages are not obvious. other third-party image loading frameworks and network request frameworks are superior in terms of simplicity and ease of use of APIs and extended functions. I recommend that you use Android-Universal-ImageLoader to load images. For network requests, android-async-http and okHttp are good choices. If you do not want to use the network request framework,AndroidHttpUtilIt is also a good choice..Maybe I didn't find it good. If a friend has any objection, please leave a message.

Volley demo address: Https://github.com/smanikandan14/Volley-demo

AndroidHttpUtilSource Code address: Https://github.com/JackCho/AndroidHttpUtil


If it is helpful to you, you are welcome to subscribe to my public account --Android sharing (ID: android_share). The QR code below provides you with timely and high quality Android dry goods.


Android development framework

Google's gson package can be used for json parsing.
The Network request and cache mechanism (generally referred to as image cache) can be viewed by volley.
The database is relatively simple. The android app is already encapsulated. But you can check FinalDb in Afinal.
The UI is useless. It is written by yourself. You can master the view and viewgroup. Basically, you can master all the controls.

Can the Volley framework of Android be used for communication with WebService?

No, you also know that velloy uses the http protocol. Webservice uses soap. Two different communication mechanisms
 

Related Article

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.