-
StringRequest request = new Stringrequest(,,,,,); JsonObjectRequest request = new JsonObjectRequest(,,,,,);查看全部
-
Volley特點: 通信更快,更簡單 Get,Post網絡請求以及網絡圖片的高效率異步處理請求 排序 網絡請求 多級別取 和Activity生命周期的聯動查看全部
-
Volley請求網絡挑選合適的對象(也就是請求網絡的返回值) StringRequest jsonObjectRequest jsonObjectRequest查看全部
-
。。。不支持上傳、下載查看全部
-
q查看全部
-
volley_post查看全部
-
volley特點查看全部
-
Volley圖片下載: 先設置一個ImageLoader String url=""; BitmapCache imageCache=new BitmapCache(); ImageLoader loader=new ImageLoader(queue,imageCache); ImageListener listener=ImageLoader.getImageListener(imageView,默認圖片,錯誤圖片,) loader.get(url,listener) 或者:使用NetworkImageView netImageView.setDefaultImageResId()默認 netImageView.setErrorImageResId()出錯時的顯示圖片 netImageView.setImageUrl(url,loader) ------------------------------------------------------ 創建圖片緩存類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) 構造方法: 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) 創建成員對象: static StringRequest request;請求對象 static Context context;上下文對象 RequestGet(xxx){ MyApplication.getHttpQueues().cancleAll(tag);//取消請求 避免重復 request=new StringRequest(Method.GET,url,vmm.loadListener,vm.errLs) request.setTag(tag) MyApplication.getHttpQueues().add(requeset); } --------------------------------------------- 創建[抽象]類,管理兩個方法: [abstract] class VolleyMethodManage; 創建成員: Context mcontext; Listener<String>mlistener,成功響應 ErrorListener merrorlistener失敗響應 定義成員方法: 提供外部方法接入: public abstract void onMySuccess(String result) public abstract void onMyError(VollyError error) 封裝成功調用: Listener<String> loadListener() { mlistener=new Listener<String> { @override void onResponse(String arg0) { onMySuccess(arg0) } }; return mListener; }查看全部
-
Volley 與Activity關聯: 在Activity的onStop方法中, MyApplication.getHttpQueues().cancleAll("abcGet"設置的Tag)查看全部
-
Volley Post請求: url 寫到?為止 StringRequest request=new StringRequest(Method.POST,url,成功響應,失敗響應){ 實現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方便圖片下載,輕量信息傳輸。 創建全局請求隊列: 創建類MyApplication繼承Application 定義static RequestQueue queues;并對外提供隊列 static RequestQueue getHttpQueues(){return queues;} 添加網絡權限并添加Application到項目清單:設置Application標簽的name屬性 Get請求: 建立請求對象:不是JSON就用StringRequest StringRequest request=new StringRequest(Method.GET,url,請求成功的回調,失敗的回調) 或者用JsonObject接收請求: JsonObjectRequest request=new JsonObjectRequest(Method.GET,url,jsonRequest請求參數,成功響應,失敗響應) 設置標簽: request.setTag("abcGet") MyApplication.getHttpQueue().add(request);將請求添加到全局隊列查看全部
-
學習目標查看全部
舉報
0/150
提交
取消