Android Common HTTP Framework Introduction

Source: Internet
Author: User
Tags connection pooling

Okhttp isSquareAn HTTP library of its own implementation, now seems to have been adopted by Google, the latest Android code to kill HttpClient, using Okhttp. Retrofit is a well-packaged, relatively developer-oriented rest request library whose underlying network requests can be handled using different network libraries, such as okhttp,httpclient. The asynchttp is also a high-level package, with httpclient at the bottom.


1, HttpURLConnection: Before the Android 2.2 version, HttpClient has fewer bugs, so using it is the best choice. httpurlconnection is the best choice for Android version 2.3 and beyond. Its API is simple and small in size, making it ideal for Android projects. Compression and caching mechanisms can effectively reduce network access to traffic, in terms of speed and power saving also played a big role. The new application should be more inclined to use httpurlconnection, because in future work we will also spend more time on the optimization httpurlconnection.
Features: Lightweight, flexible, easy to scale, improved in 3.0 and 4.0, such as HTTPS support, and support for caching in 4.0. 2, HttpClient: efficient and stable, but the maintenance cost is high, so the Android development team is not willing to maintain the library but instead of a more lightweight httpurlconnection. 3, Okhttp:okhttp is a Java http+spdy client development package, but also supports Android. Requires Android 2.3 or more. Features: Okhttp is an Android HTTP client that is highly efficient and supports spdy, connection pooling, gzip, and HTTP caching. By default, Okhttp automatically handles common network problems, such as two-connection, SSL handshake issues. If you have integrated Okhttp,retrofit in your application, the default is to use Okhttp to handle other network layer requests. The underlying implementation of HttpURLConnection starting with Android4.4 is okhttp. 4, Volley: The early use of httpclient, later use HttpURLConnection, is the Google 2013 launch of the network request framework, is very suitable for the data volume is not small, but the traffic is frequent network operation, and for the large data volume of the network operation, such as downloading files and so on, volley's performance will be very bad. 5, Retrofit: and volley framework request way very similar, the bottom network request uses okhttp, uses the annotation way to specify the request method and the URL address, reduces the code quantity.

1, VolleyProject Address Https://github.com/smanikandan14/Volley-demo(1) asynchronous download of JSON, image, etc.;(2) Ordering of network requests (scheduling)(3) Priority processing of network requests(4) Cache(5) Multi-level cancellation request(6) Linkage with activity and life cycle (simultaneous cancellation of all network requests at end of activity)
2, Android-async-httpProject Address: https://github.com/loopj/android-async-httpDocument Description: http://loopj.com/android-async-http/(1) Processing request results in an anonymous callback(2) making HTTP requests outside the UI thread(3) file breakpoint upload(4) Smart retry(5) Default gzip compression(6) Support parsing into JSON format(7) Cookies can be persisted to sharedpreferences
3. Afinal FrameProject Address: https://github.com/yangfuhai/afinalThere are four main modules:(1) Database module: An ORM framework in Android that uses a thread pool to manipulate SQLite. (2) Note module: The IOC framework in Android, which can be used for UI binding and event binding in a fully annotated manner. No need for Findviewbyid and Setclicklistener. (3) Network module: encapsulation HTTP data request through HttpClient, support Ajax mode loading, support downloading and uploading file function. (4) Picture cache module: When loading bitmap through Finalbitmap,imageview, there is no need to consider the phenomenon of image dislocation when the Oom and Android containers appear during the bitmap loading process. Finalbitmap can configure the number of thread preempted threads, cache size, cache path, load display animation, etc. Finalbitmap's memory management uses the LRU algorithm,not using weak references (after android2.3, Google has not recommended the use of weak references, android2.3 after the forced recovery of soft and weak references, details of the official Android document),better management of bitmap memory. Finalbitmap can customize the downloader to extend other protocols to display network pictures, such as FTP. You can also customize the bitmap display,Play animations when ImageView display pictures (the default is the gradient animation display).
4. Xutils FrameProject Address: Https://github.com/wyouflf/xUtilsThere are four main modules:(1) Database module: The ORM Framework in Android, a line of code can be used to increase the deletion of the search;support transactions, closed by default;annotations can be used to customize table names, column names, foreign keys, uniqueness constraints, NOT NULL constraints, check constraints, etc. (Please note the table and column names when confusion is required);support for binding foreign keys, saving entities when the foreign key associated entities are automatically saved or updated;automatic loading of foreign key associated entities, support delay loading;support chain expression query, more intuitive query semantics, refer to the following introduction or sample examples. (2) Note module: The IOC framework in Android, full annotation can be UI, resource and event binding;new Event Binding mode, the use of obfuscation tools can still work properly;currently supports 20 commonly used event bindings, see Viewcommoneventlistener Class and package com.lidroid.xutils.view.annotation.event. (3) network module: Support synchronous, asynchronous way of request;support large file upload, upload large files will not oom;support Get,post,put,move,copy,delete,head,options,trace,connect request;Download Support 301/302 Redirect, support setting whether to rename downloaded files according to content-disposition;a request to return text content (by default, only get requests enabled) supports caching, setting the default expiration time and the expiration time for the current request. (4) Picture cache module: When loading the bitmap, there is no need to consider the phenomenon of the image dislocation when the Oom and the Android container move quickly during the bitmap loading process .support to load network pictures and local images;the memory management uses the LRU algorithm, better manages the bitmap memory;Configurable line preempted thread count, cache size, cache path, load display animation, etc. ..
5, ThinkandroidProject Address: https://github.com/white-cat/ThinkAndroidThe main modules are:(1) MVC module: Implementing the separation of views from the model. (2) IOC module: The IOC module in Android, fully annotated to enable UI binding, reading of resources in Res, and initialization of objects. (3) database module: An ORM framework in Android that uses a thread pool to manipulate SQLite. (4) HTTP module: Encapsulates HTTP data requests via HttpClient and supports asynchronous and synchronous loading. (5) Cache module: Through simple configuration and design can be very good cache, the cache can be arbitrarily configured(6) Image cache module: ImageView loading pictures without taking into account the image during the loading process of oom and the Android container rapid sliding when the picture dislocation and other phenomena. (7) Configurator module: can be easy to implement pairing configuration operation, the current configuration file can support preference, the properties of the configuration to access. (8) Log printing module: Can be faster and easy to achieve log printing, support for the expansion of log printing, currently supports sdcard write local printing, and console printing(9) Download module: Can be easily implemented multi-threaded download, background download, breakpoint continuation, download control, such as Start, pause, delete and so on. (10) Network status Detection module: When the network status changes, it is checked
6, LoonandroidProject Address: https://github.com/gdpancheng/LoonAndroidThe main modules are:(1) Auto-inject frame (only need to inherit the application within the frame)(2) Picture loading frame (multi-cache, automatic recovery, maximum memory security)(3) Network request module (inherits basically all HTTP requests now)(4) Eventbus (integration of an open source framework)(5) Validation Framework (integrated open source framework)(6) JSON parsing (supports parsing into collections or objects)(7) database (I don't know who wrote it and forgot it)(8) Multi-threaded breakpoint Download (automatically determine whether to support multi-threading, to determine whether it is redirected)(9) Automatic Update module(10) A series of tool classes

From for notes (Wiz)

Android Common HTTP Framework Introduction

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.