Google I/O 2013 – Volley: Easy, Fast Networking for Android
1、什么是volley
2、volley能做什么
- JSON对象
- 图片加载
Advantages of using Volley:
- Volley automatically schedule all network requests. It means that Volley will be taking care of all the network requests your app executes for fetching response or image from web.
- Volley provides transparent disk and memory caching.
- Volley provides powerful cancellation request API. It means that you can cancel a single request or you can set blocks or scopes of requests to cancel.
- Volley provides powerful customization abilities.
- Volley provides Debugging and tracing tools
3、volley架构
Volley使用了线程池来作为基础结构,主要分为主线程,cache线程和network线程。主线程和cache线程都只有一个,而NetworkDispatcher线程可以有多个,这样能解决比并行问题。具体可以参考下图,此图节选自Google I/O 演讲。
4、使用volley
4.1 获取volley
引入Volley非常简单,首先,从git库先克隆一个下来:
git clone https://android.googlesource.com/platform/frameworks/volley
然后编译为jar包,再在自己的工程里import进来。如果git下载失败可以在这下载。 VolleyLib
4.2 JsonObjectRequest 简单文本请求
mRequestQueue = Volley.newRequestQueue(this);
String url = "http://pipes.yahooapis.com/pipes/pipe.run?_id=giWz8Vc33BG6rQEQo_NLYQ&_render=json";
pd = ProgressDialog.show(this,"Please Wait...","Please Wait..."); JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET,url,null,new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG,response.toString());
parseJSON(response);
va.notifyDataSetChanged();
pd.dismiss();
}
},new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i(TAG,error.getMessage());
}
});
mRequestQueue.add(jr);
4.3 ImageView
RequestQueue mRequestQueue = Volley.newRequestQueue(this);
final LruCache<String, Bitmap> mImageCache = new LruCache<String, Bitmap>(
20);
ImageCache imageCache = new ImageCache() {
@Override
public void putBitmap(String key, Bitmap value) {
mImageCache.put(key, value);
} @Override
public Bitmap getBitmap(String key) {
return mImageCache.get(key);
}
};
ImageLoader mImageLoader = new ImageLoader(mRequestQueue, imageCache);
// imageView是一个ImageView实例
// ImageLoader.getImageListener的第二个参数是默认的图片resource id
// 第三个参数是请求失败时候的资源id,可以指定为0
ImageListener listener = ImageLoader
.getImageListener(imageView, android.R.drawable.ic_menu_rotate,
android.R.drawable.ic_delete);
mImageLoader.get("http://a.hiphotos.baidu.com/album/h%3D800%3Bcrop%3D0%2C0%2C1280%2C800/sign=5f024b518326cffc762ab2b2893a29e2/72f082025aafa40fa3bcf315aa64034f79f019fb.jpg", listener);
4.4 NetworkImageView
NetworkImageView是继承自ImageView,是Volley提供的一个全新的简单加载图片的控件。
NetworkImageView netImgView=(NetworkImageView)findViewById(R.id.volley_img_networkimgeview);
netImgView.setTag("url"); netImgView.setImageUrl("http://a.hiphotos.baidu.com/album/h%3D800%3Bcrop%3D0%2C0%2C1280%2C800/sign=5f024b518326cffc762ab2b2893a29e2/72f082025aafa40fa3bcf315aa64034f79f019fb.jpg",mImageLoader);
参考:
Google I/O 2013 – Volley: Easy, Fast Networking for Android(ppt)
Google I/O 2013 – Volley: Easy, Fast Networking for Android的更多相关文章
- Google官方网络框架Volley实战——QQ吉凶测试,南无阿弥陀佛!
Google官方网络框架Volley实战--QQ吉凶测试,南无阿弥陀佛! 这次我们用第三方的接口来做一个QQ吉凶的测试项目,代码依然是比较的简单 无图无真相 直接撸代码了,详细解释都已经写在注释里了 ...
- Google官方网络框架-Volley的使用解析Json以及加载网络图片方法
Google官方网络框架-Volley的使用解析Json以及加载网络图片方法 Volley是什么? Google I/O 大会上,Google 推出 Volley的一个网络框架 Volley适合什么场 ...
- 利用百度词典API和Volley网络库开发的android词典应用
关于百度词典API的说明,地址在这里:百度词典API介绍 关于android网络库Volley的介绍说明,地址在这里:Android网络通信库Volley 首先我们看下大体的界面布局!
- 在Visual Studio 2013/2015上使用C#开发Android/IOS安装包和操作步骤
Xamarin 配置手册和离线包下载 http://pan.baidu.com/s/1eQ3qw8a 具体操作: 安装前提条件 1. 安装Visual Studio 2013,安装过程省略,我这里安装 ...
- [转发]在Visual Studio 2010/2012/2013/2015上使用C#开发Android/IOS安装包和操作步骤
官方学习文档:http://developer.xamarin.com/guides/android/getting_started/ 官方学习例子:http://developer.xamarin. ...
- 2013 HTML5中国峰会演讲:Android上的HTML5:过去,现在和将来
转载请注明原文地址:http://blog.csdn.net/milado_nju ## 会议链接(应用和工具专场) http://2013.html5dw.com/main, 2013年8月10日 ...
- Unity上线google商店 用IL2Cpp打包64位版本和Android APP Bundle优化 及产生的bug
ios刚上线,这边着手改成android版本,我开始使用的是unity2017.4.1版本 上传谷歌商店是出现这两个警告: 要支持64位,但是在2017版本上没有找到64位的打包选项,猜测应该是版本的 ...
- volley框架 出现at com.android.volley.Request.<init>
请求json数据的时候出现这种情况: 原因: // 访问网络,初始化详情 JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET ...
- 开发一款高端大气上档次的android应用需要必备的知识——记于2013年末
Android入门还是很简单的,看两本书,翻阅几篇文章,搭建了开发环境就算入门了.可是怎样开发一款完备的android应用呢,开发一款高端的android应用又需要那些知识呢,作者根据几年的开发经验做 ...
随机推荐
- java基础讲解02-----eclipse快捷方式(2017-04-12 23:47)
ctrl + shift+o 出去多余的引用包 ctrl+i 修改格式
- 利用 meta 标签重定向
页面定期刷新,如果加url的,则会重新定向到指定的网页,content后面跟的是时间(单位秒),把这句话加到指定网页的<head></head>里一般也用在实时性很强的应用 ...
- python selenium --鼠标事件
转自:http://www.cnblogs.com/fnng/p/3288444.html 本节重点: ActionChains 类 context_click() 右击 double_click( ...
- android UI 适配小节
一. 像素密度表 像素密度表 比如UE 给了三张切图分别对应: mdpi, xhdpi, xxdpi 10 * 10, 20 * 20, 30 * 30 上面的值都 ...
- Android:实现手势滑动的事件处理方法
首先得Activity必须实现OnGestureListener接口,该接口提供了关于手势操作的一些方法, onDown方法:onDown是,一旦触摸屏按下,就马上产生onDown事件 ...
- unity, remove a scene from build settings
把scene添加到build settings的scenes in build列表里以后,如果想删除,没有菜单可用,但选中按delete即可. 参考:http://answers.unity3d.co ...
- Powershell分支条件
Where-Object 进行条件判断很方便,如果在判断后执行很多代码可以使用IF-ELSEIF-ELSE语句.语句模板: If(条件满足){如果条件满足就执行代码}Else{如果条件不满足}条件判断 ...
- 跟着百度学PHP[14]-PDO的预处理语句1
预处理语句有以下两个特点: 1.效率高 2.安全性好 为什么说预处理语句效率高呢? 预处理语句就好比一个模板,比如下面的一串插入语句: insert into admin(id,username,pa ...
- 在oschina添加了x3dom的索引
http://www.x3dom.org/ http://www.oschina.net/p/x3dom x3dom的思路非常优秀并且可行,借助于WebGL的春风,将X3D带到了死而复生的境地.
- 使用心跳机制实现CS架构下多客户端的在线状态实时更新以及掉线自动重连
此文讲述的内容是一个实际项目开发中的一部分内容,笔者将亲身经历写成文章. [背景] 现需要实现这样的功能:有多个客户端连着同一个服务器.服务器和客户端之间需要“互相”知道彼此的连接状态.比如在某一时刻 ...