Advertisement
mhnds

Untitled

Oct 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. package com.example.innovare.scrollhorizontal;
  2.  
  3. /**
  4. * Created by innovare on 9/11/15.
  5. */
  6. import android.app.Application;
  7. import android.text.TextUtils;
  8.  
  9. import com.android.volley.Request;
  10. import com.android.volley.RequestQueue;
  11. import com.android.volley.toolbox.Volley;
  12.  
  13. public class AppController extends Application {
  14.  
  15. public static final String TAG = AppController.class.getSimpleName();
  16.  
  17. private RequestQueue mRequestQueue;
  18.  
  19. private static AppController mInstance;
  20.  
  21. @Override
  22. public void onCreate() {
  23. super.onCreate();
  24. mInstance = this;
  25. }
  26.  
  27. public static synchronized AppController getInstance() {
  28. return mInstance;
  29. }
  30.  
  31. public RequestQueue getRequestQueue() {
  32. if (mRequestQueue == null) {
  33. mRequestQueue = Volley.newRequestQueue(getApplicationContext());
  34. }
  35.  
  36. return mRequestQueue;
  37. }
  38.  
  39. public <T> void addToRequestQueue(Request<T> req, String tag) {
  40. req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
  41. getRequestQueue().add(req);
  42. }
  43.  
  44. public <T> void addToRequestQueue(Request<T> req) {
  45. req.setTag(TAG);
  46. getRequestQueue().add(req);
  47. }
  48.  
  49. public void cancelPendingRequests(Object tag) {
  50. if (mRequestQueue != null) {
  51. mRequestQueue.cancelAll(tag);
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement