How to create VolleySingleton class in Android java?

Example code to create VolleySingleton class which is used to load network image and to connect to external network server
package com.indiacitys.cityclassifieds; /** * Created by Murali on 8/17/2015. */ import; import; import; import; import; public class VolleySingleton { private static VolleySingleton mInstance = null; private RequestQueue mRequestQueue; private ImageLoader mImageLoader; private VolleySingleton(){ mRequestQueue = Volley.newRequestQueue(MainActivity.getAppContext()); mImageLoader = new ImageLoader(this.mRequestQueue, new ImageLoader.ImageCache() { private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10); public void putBitmap(String url, Bitmap bitmap) { mCache.put(url, bitmap); } public Bitmap getBitmap(String url) { return mCache.get(url); } }); } public static VolleySingleton getInstance(){ if(mInstance == null){ mInstance = new VolleySingleton(); } return mInstance; } public RequestQueue getRequestQueue(){ return this.mRequestQueue; } public ImageLoader getImageLoader(){ return this.mImageLoader; } }
Sign In or Register to comment.