Android Volley ?????????????
???????????? ???????[ 2015/7/23 10:58:30 ] ???????????????
????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???????????????д???棬????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11