Last active
December 1, 2016 09:55
-
-
Save IevgenOsetrov/8d13080b5337f81b3b54564bff75d0b8 to your computer and use it in GitHub Desktop.
Volley Singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class VolleySingleton { | |
private static VolleySingleton mInstance; | |
private RequestQueue mRequestQueue; | |
private static Context mContext; | |
private VolleySingleton(Context context) { | |
mContext = context; | |
mRequestQueue = getRequestQueue(); | |
} | |
public static synchronized VolleySingleton getInstance(Context context) { | |
if (mInstance == null) { | |
mInstance = new VolleySingleton(context); | |
} | |
return mInstance; | |
} | |
public RequestQueue getRequestQueue() { | |
if (mRequestQueue == null) { | |
mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext()); | |
} | |
return mRequestQueue; | |
} | |
public <T> void addToRequestQueue(Request<T> req) { | |
getRequestQueue().add(req); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment