Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Controller extends Application {
- private static final String TAG = Application.class.getSimpleName();
- private static Controller instance;
- RequestQueue mRequestQueue;
- @Override
- public void onCreate() {
- super.onCreate();
- instance = this;
- }
- public static synchronized Controller getInstance(){
- return instance;
- }
- private RequestQueue getRequestQueue(){
- if (mRequestQueue == null){
- mRequestQueue = Volley.newRequestQueue(getApplicationContext());
- }
- return mRequestQueue;
- }
- public <T> void addToRequestQueue(Request<T> req, String tag){
- req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
- getRequestQueue().add(req);
- }
- public <T> void addToRequestQueue (Request<T> req){
- req.setTag(TAG);
- getRequestQueue().add(req);
- }
- public void cancelAllRequest(Object req){
- if (mRequestQueue != null){
- mRequestQueue.cancelAll(req);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment