use of com.android.volley.toolbox.DiskBasedCache in project BestPracticeApp by pop1234o.
the class MainActivity method requestVolley2.
/**
* 自己配置请求client
*/
private void requestVolley2() {
RequestQueue mRequestQueue;
// Instantiate the cache
// 1MB cap
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024);
// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());
// Instantiate the RequestQueue with the cache and network.
mRequestQueue = new RequestQueue(cache, network);
// Start the queue
mRequestQueue.start();
String url = "http://www.example.com";
// Formulate the request and handle the response.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Do something with the response
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Handle error
}
});
// Add the request to the RequestQueue.
mRequestQueue.add(stringRequest);
}
use of com.android.volley.toolbox.DiskBasedCache in project fresco by facebook.
the class SampleVolleyFactory method getRequestQueue.
public static RequestQueue getRequestQueue(Context context) {
if (sRequestQueue == null) {
File cacheDir = new File(context.getCacheDir(), VOLLEY_CACHE_DIR);
sRequestQueue = new RequestQueue(new DiskBasedCache(cacheDir, ConfigConstants.MAX_DISK_CACHE_SIZE), new BasicNetwork(new HurlStack()));
sRequestQueue.start();
}
return sRequestQueue;
}
use of com.android.volley.toolbox.DiskBasedCache in project OkVolley by googolmo.
the class OkVolley method newRequestQueue.
public static RequestQueue newRequestQueue(Context context) {
if (InstanceNetwork == null) {
InstanceNetwork = new OkNetwork(getDefaultHttpStack());
}
if (InstanceCache == null) {
File cache = context.getExternalCacheDir();
if (cache == null) {
cache = context.getCacheDir();
}
File cacheDir = new File(cache, DEFAULT_CACHE_DIR);
InstanceCache = new DiskBasedCache(cacheDir);
}
RequestQueue queue = new RequestQueue(InstanceCache, InstanceNetwork);
queue.start();
return queue;
}
use of com.android.volley.toolbox.DiskBasedCache in project Douya by DreaminginCodeZH.
the class Volley method createAndStartRequestQueue.
/**
* @see com.android.volley.toolbox.Volley#newRequestQueue(Context, HttpStack)
*/
private void createAndStartRequestQueue() {
mRequestQueue = new RequestQueue(new DiskBasedCache(new File(DouyaApplication.getInstance().getCacheDir(), "volley")), new BasicNetwork(new HurlStack()));
mRequestQueue.start();
}
use of com.android.volley.toolbox.DiskBasedCache in project malp by gateship-one.
the class MALPRequestQueue method getInstance.
public static synchronized MALPRequestQueue getInstance(Context context) {
if (null == mInstance) {
Network network = new BasicNetwork(new HurlStack());
// 10MB disk cache
Cache cache = new DiskBasedCache(context.getCacheDir(), 1024 * 1024 * 10);
mInstance = new MALPRequestQueue(cache, network);
mInstance.start();
}
return mInstance;
}
Aggregations