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 android.graphics.Bitmap; import android.support.v4.util.LruCache; import com.android.volley.RequestQueue; import com.android.volley.toolbox.ImageLoader; import com.android.volley.toolbox.Volley; 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.