标签:
在学习中注意点:
1、要在AndroidManifest.xml中加入上网允许权限
<uses-permission android:name="android.permission.INTERNET"/>
MySingleton.java
public class MySingleton {
private static MySingleton mInstance;
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
private static Context mCtx;
@SuppressLint("NewApi")
private MySingleton(Context context){
mCtx = context;
mRequestQueue = getRequestQueue();
mImageLoader = new ImageLoader(mRequestQueue,new ImageCache() {
private final LruCache<String,Bitmap>
cache = new LruCache<String,Bitmap>(20);
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@SuppressLint("NewApi")
@Override
public void putBitmap(String url, Bitmap bitmap) {
cache.put(url, bitmap);
}
@Override
public Bitmap getBitmap(String url) {
return cache.get(url);
}
});
}
public static synchronized MySingleton getInstance(Context context){
if(mInstance == null){
mInstance = new MySingleton(context);
}
return mInstance;
}
public RequestQueue getRequestQueue(){
if(mRequestQueue == null){
// getApplicationContext() is key, it keeps you from leaking the
// Activity or BroadcastReceiver if someone passes one in.
mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req){
getRequestQueue().add(req);
}
public ImageLoader getImageLoader(){
return mImageLoader;
}
}
官方学习网站:
http://developer.android.com/training/volley(经常打不开)
http://www.cnblogs.com/bvin/p/4350731.html(博主的官方摘录)
分享总结:
http://blog.csdn.net/guolin_blog/article/details/17482095(Volley完全解析一~四)
http://blog.csdn.net/chenfuduo_loveit/article/details/41773607(博主的译文)
http://codekk.com/open-source-project-analysis/detail/Android/grumoon/Volley%20%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90(codeKK的源码解析)
标签:
原文地址:http://blog.csdn.net/zhanhong39/article/details/44917167