/**
* Creates a default instance of the worker pool and calls {@link RequestLauncher#start()} on it.
* You may set a maximum size of the disk cache in bytes.
*
* @param context A {@link Context} to use for creating the cache dir.
* @param stack An {@link HttpStack} to use for the network, or null for default.
* @param maxDiskCacheBytes the maximum size of the disk cache, in bytes. Use -1 for default size.
* @return A started {@link RequestLauncher} instance.
*/
public static RequestLauncher newLauncher(Context context, HttpStack stack, int maxDiskCacheBytes) {
File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
String userAgent = "volley/0";
try {
String packageName = context.getPackageName();
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
userAgent = packageName + "/" + info.versionCode;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
if (stack == null) {
if (Build.VERSION.SDK_INT >= 9) {
stack = new HurlStack();
} else {
// Prior to Gingerbread, HttpUrlConnection was unreliable.
// See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
}
}
Network network = new BasicNetwork(stack);
RequestLauncher launcher;
if (maxDiskCacheBytes <= -1) {
// No maximum size specified
launcher = new RequestLauncher(new DiskBasedCache(cacheDir), network);
} else {
// Disk cache size specified
launcher = new RequestLauncher(new DiskBasedCache(cacheDir, maxDiskCacheBytes), network);
}
launcher.start();
return launcher;
}
Volley.java 文件源码
java
阅读 36
收藏 0
点赞 0
评论 0
项目:core-http
作者:
评论列表
文章目录