????Volley????
????Google I/O 2013 ?????????? Android ??????????????????????
???????贸??????????????小???????????????????
????git clone https://android.googlesource.com/platform/frameworks/volley">https://android.googlesource.com/platform/frameworks/volley
????Volley???
 

????Volley Architect
????????????????Volley??????????????????????????????????????????
???????????????????????泻?????????UI????1??????Cache????1??????Network?????????4??????
????UI????????????????????????????
????Cache???????榛�?妫�???泻??????????????????????
????Network???????????????NetworkDispatcher????????????????小?size?????????些????????????????????????????谢??????械????????????????????????UI????
???????????????????????
????Volley.java??Volley?????????????? newRequestQueue(…) ??????????????????????RequestQueue??
????Request????????????StringRequest??JsonRequest??ImageRequest ?????????????????????????????????????
????RequestQueue.java????????校???????????CacheDispatcher(???????????????????????)??NetworkDispatcher????(????????????????????????)?????ResponseDelivery(????????????)????? start() ?????????????CacheDispatcher??NetworkDispatchers??
?????????????????蟹?????????
????public static RequestQueue newRequestQueue(Context context?? HttpStack stack) {
????...
????Network network = new BasicNetwork(stack);
????RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir)?? network);
????queue.start();
????return queue;
????}
??????????????????????????????
????HttpStack.java??????HTTP??????????????????Volley???谢??? HttpURLConnection ?? HurlStack ?? ???? Apache HttpClient ??HttpClientStack??
????Network.java??????HttpStack??????????????????????ResponseDelivery?????NetworkResponse??
????Cache.java??????????????Volley????????????sdcard?????DiskBasedCache??NetworkDispatcher????????????卸????????娲�?? Cache??CacheDispatcher??? Cache ???????????
????????Network???HttpStatck?????newRequestQueue?????stack?null??API Level >= 9????????? HttpURLConnection ?? HurlStack??小?? 9????????? HttpClient ?? HttpClientStack??
????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));
????}
????}
????????HTTP?????HttpStatck?????????澹�???????OKHTTP?????????渭???????????????OKHttp????Volley????HTTP????
??????????????????????????
????public void start() {
????stop();  // Make sure any currently running dispatchers are stopped.
????// Create the cache dispatcher and start it.
????mCacheDispatcher = new CacheDispatcher(mCacheQueue?? mNetworkQueue?? mCache?? mDelivery);
????mCacheDispatcher.start();
????// Create network dispatchers (and corresponding threads) up to the pool size.
????for (int i = 0; i < mDispatchers.length; i++) {
????NetworkDispatcher networkDispatcher = new NetworkDispatcher(mNetworkQueue?? mNetwork??
????mCache?? mDelivery);
????mDispatchers[i] = networkDispatcher;
????networkDispatcher.start();
????}
????}
????CacheDispatcher.java???????Thread????????????????????????????????????????????????????????????????????????????????????ResponseDelivery???泻?????????????未????????????效?????????渭?????锟�?????????????????NetworkDispatcher?????????
????NetworkDispatcher.java???????Thread?????????????????????????????????????????????????????????????????????????????????????ResponseDelivery???泻???????????卸??????????谢??妾�
????ResponseDelivery.java??????????interface??postResponse???postError??
???????????????????Volley???????
?????????????????????????
????????????????????????CacheDispatcher??????????????????????????????校???????????????????????????????????
????????????????未???校???????????????????校??????????????NetworkDispatcher??????????HTTP???????????????写???妫�????????????????