Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.thomas.taken.app;
- import android.app.Application;
- import android.text.TextUtils;
- import com.android.volley.Request;
- import com.android.volley.RequestQueue;
- import com.android.volley.toolbox.Volley;
- public class AppController extends Application {
- public static final String TAG = AppController.class.getSimpleName();
- private RequestQueue mRequestQueue;
- private static AppController mInstance;
- @Override
- public void onCreate() {
- super.onCreate();
- mInstance = this;
- }
- // Instantiate the RequestQueue.
- public static synchronized AppController getInstance() {
- return mInstance;
- }
- // getApplicationContext() is key, it keeps you from leaking the
- // Activity or BroadcastReceiver if someone passes one in.
- public 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 cancelPendingRequests(Object tag) {
- if (mRequestQueue != null) {
- mRequestQueue.cancelAll(tag);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment