-
StringRequest request = new Stringrequest(,,,,,); JsonObjectRequest request = new JsonObjectRequest(,,,,,);查看全部
-
Volley特點: 通信更快,更簡單 Get,Post網(wǎng)絡(luò)請求以及網(wǎng)絡(luò)圖片的高效率異步處理請求 排序 網(wǎng)絡(luò)請求 多級別取 和Activity生命周期的聯(lián)動查看全部
-
Volley請求網(wǎng)絡(luò)挑選合適的對象(也就是請求網(wǎng)絡(luò)的返回值) StringRequest jsonObjectRequest jsonObjectRequest查看全部
-
。。。不支持上傳、下載查看全部
-
q查看全部
-
volley_post查看全部
-
volley特點查看全部
-
Volley圖片下載: 先設(shè)置一個ImageLoader String url=""; BitmapCache imageCache=new BitmapCache(); ImageLoader loader=new ImageLoader(queue,imageCache); ImageListener listener=ImageLoader.getImageListener(imageView,默認(rèn)圖片,錯誤圖片,) loader.get(url,listener) 或者:使用NetworkImageView netImageView.setDefaultImageResId()默認(rèn) netImageView.setErrorImageResId()出錯時的顯示圖片 netImageView.setImageUrl(url,loader) ------------------------------------------------------ 創(chuàng)建圖片緩存類BitmapCache : BitmapCache implements ImageCache; 成員變量: LruCache<String,Bitmap> cache; int max=10*1024*1024//10M大小 重寫: getBitmap(String arg0) return cache.get(arg0) putBitmap(string arg0,Bitmap arg1) cache.put(arg0,arg1) 構(gòu)造方法: BitmapCache(){ cache=new LruCache<String,Bitmap>(max) { @override int sizeOf(String key,Bitmap value) { return value.getRowBytes()*value.getHeight(); }查看全部
-
Volley請求圖片: ImageRequest request=new ImageRequest(url,成功,寬0,高0,Config.RGB_565,失?。?成功:onResponse(Bitmap arg0)查看全部
-
建立請求隊列查看全部
-
Volley簡單二次封裝: 定義請求類: VolleyRequest 定義成員方法: static void RequestGet(Context mcontext,String url,String tag,VollaeyMethodManage vmm ) static void RequestPost(Context mcontext,String url,String tag,Map<String,String>,VollaeyMethodManage vmm) 創(chuàng)建成員對象: static StringRequest request;請求對象 static Context context;上下文對象 RequestGet(xxx){ MyApplication.getHttpQueues().cancleAll(tag);//取消請求 避免重復(fù) request=new StringRequest(Method.GET,url,vmm.loadListener,vm.errLs) request.setTag(tag) MyApplication.getHttpQueues().add(requeset); } --------------------------------------------- 創(chuàng)建[抽象]類,管理兩個方法: [abstract] class VolleyMethodManage; 創(chuàng)建成員: Context mcontext; Listener<String>mlistener,成功響應(yīng) ErrorListener merrorlistener失敗響應(yīng) 定義成員方法: 提供外部方法接入: public abstract void onMySuccess(String result) public abstract void onMyError(VollyError error) 封裝成功調(diào)用: Listener<String> loadListener() { mlistener=new Listener<String> { @override void onResponse(String arg0) { onMySuccess(arg0) } }; return mListener; }查看全部
-
Volley 與Activity關(guān)聯(lián): 在Activity的onStop方法中, MyApplication.getHttpQueues().cancleAll("abcGet"設(shè)置的Tag)查看全部
-
Volley Post請求: url 寫到?為止 StringRequest request=new StringRequest(Method.POST,url,成功響應(yīng),失敗響應(yīng)){ 實現(xiàn)getParams()方法 getParams{ Map<string,string>hashMap=new HashMap<String,String>(); hashMap.put("phone",12346); hashMap.put("key","akjhdfhjg") return hashMap; } } 或者使用JsonObject JsonObject object=new JsonObject(hashMap); JsonObjectRequest request=new JsonObjectRequest(Method.POST,object,成功,失敗) request.setTag("abcPost") MyApplication.getHttpQueues().add(request);查看全部
-
Volley方便圖片下載,輕量信息傳輸。 創(chuàng)建全局請求隊列: 創(chuàng)建類MyApplication繼承Application 定義static RequestQueue queues;并對外提供隊列 static RequestQueue getHttpQueues(){return queues;} 添加網(wǎng)絡(luò)權(quán)限并添加Application到項目清單:設(shè)置Application標(biāo)簽的name屬性 Get請求: 建立請求對象:不是JSON就用StringRequest StringRequest request=new StringRequest(Method.GET,url,請求成功的回調(diào),失敗的回調(diào)) 或者用JsonObject接收請求: JsonObjectRequest request=new JsonObjectRequest(Method.GET,url,jsonRequest請求參數(shù),成功響應(yīng),失敗響應(yīng)) 設(shè)置標(biāo)簽: request.setTag("abcGet") MyApplication.getHttpQueue().add(request);將請求添加到全局隊列查看全部
-
學(xué)習(xí)目標(biāo)查看全部
舉報
0/150
提交
取消