android http 架構volley 的學習 。。

來源:互聯網
上載者:User

標籤:架構   android   程式碼片段   json   cache   

Volley 下載 

  1. git clone https://android.googlesource.com/platform/frameworks/volley       
下載之後引入項目即可 ,volley 適合資料小但是連續的通訊,,至於下載檔案就支援的不是很好,建議用android 內建的downLoadmanager ,.android 連網需要的網路許可權,和對儲存卡的讀寫權限是不能缺少的。。。 Volley 中用的最多的也就Volley.class,StringRequest,JsonRequest,ImageRequest.當然你也可以自己實現。繼承Request<T>即可。。一般在項目中開發還需要自訂Volley.class 。例如 自訂的on-disk cache directory , userAgent, 可以修改volley原項目的檔案,或者自訂MyVolley。兩種方法自己選擇。。擷取百度首頁的源碼
StringRequest  request = new StringRequest(host, new Listener<String>() {@Overridepublic void onResponse(String response) {Logg.logg("請求成功運行 ");// 輸出結果 。。。。。Logg.logg(response);}}, new Response.ErrorListener() {@Overridepublic void onErrorResponse(VolleyError error) {                     Logg.logg("請求錯誤運行 ");}});queue.add(request);queue.start() ;
擷取json 
JsonObjectRequest objectRequest = new JsonObjectRequest(json, null, new Response.Listener<JSONObject>() {@Overridepublic void onResponse(JSONObject response) { Logg.logg(response.toString());}}, null);queue.add(objectRequest);queue.start() ;
從網路載入圖片不要用imageview ,而要用NetWorkImageView .. 並且要實現imagecache ..建議 .
post請求 需要重寫StringRequest 中的getParam 方法,, demo 。。http://download.csdn.net/detail/u014781439/8324529


android http 架構volley 的學習 。。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.