Volley框架關於RequestQueue的心得
阿新 • • 發佈:2019-02-16
class MySingleton{
private static MySingleton mInstance;
private RequestQueue mRequestQueue;
private static Context mCtx;
private MySingleton(Context context){
mCtx=context;
mRequestQueue=getRequestQueue();
}
public static synchronized MySingleton getInstance(Context context){
if(mInstance == null){
mInstance=new MySingleton(context);
}
return mInstance;
}
public RequestQueue getRequestQueue(){
if(mRequestQueue==null){
mRequestQueue=Volley.newRequestQueue(mCtx.getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req) {
getRequestQueue().add(req);
}
}
private static MySingleton mInstance;
private RequestQueue mRequestQueue;
private static Context mCtx;
private MySingleton(Context context){
mCtx=context;
mRequestQueue=getRequestQueue();
}
public static synchronized MySingleton getInstance(Context context){
if(mInstance == null){
mInstance=new MySingleton(context);
}
return mInstance;
}
public RequestQueue getRequestQueue(){
if(mRequestQueue==null){
mRequestQueue=Volley.newRequestQueue(mCtx.getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req) {
getRequestQueue().add(req);
}
}