Volley学习(网摘)

Android网络通信架构——Volleyjava

一、 Volley提供的功能
简单来讲,它提供了以下的便利功能:android

    • JSON,图像等的异步下载;
    • 网络请求的排序(scheduling)
    • 网络请求的优先级处理
    • 缓存
    • 多级别取消请求
    • 和Activity和生命周期的联动(Activity结束时同时取消全部网络请求)

二、学习前的准备:下载volley源码打成jar包(我经过这个网址下载不下了,可是网络上不少好心人已经分享了源码)git

下载地址:缓存

mirror of volley library from android source网络

from :
https://android.googlesource.com/platform/frameworks/volley架构

original:
git clone https://android.googlesource.com/platform/frameworks/volley异步

update weekly from android source repoide

 

三、正式开工学习

  简单例子:this

private void getStringVolley() {
		RequestQueue requestQueue = Volley.newRequestQueue(this);
		StringRequest sRequest=new StringRequest(Request.Method.GET,CITY_CODE_URL, new Listener<String>() {

			@Override
			public void onResponse(String response) {
				System.out.println(response);				
			}
		}, new Response.ErrorListener() {
			@Override
			public void onErrorResponse(VolleyError arg0) {
				System.out.println("sorry,Error");
			}
		});
		sRequest.setShouldCache(false);
		requestQueue.add(sRequest);
	}
相关文章
相关标签/搜索