天天看點

android open source project Plug-in 11.24

Volley 學習詳細文章:詳解

我們的應用需要和伺服器互動資料 我們需要通過URL去請求伺服器,伺服器在傳回資料

于是在我們應用中可以這樣設計: 我們可以設計一個請求器,這個請求器是程式中獨有的,這樣我們就可以設計成一個單例模式.

public class RequestManager {
    public static RequestQueue mRequestQueue = Volley.newRequestQueue(App.getContext());

    private RequestManager() {
        // no instances
    }

    public static void addRequest(Request<?> request, Object tag) {
        if (tag != null) {
            request.setTag(tag);
        }
        mRequestQueue.add(request);
    }

    public static void cancelAll(Object tag) {
        mRequestQueue.cancelAll(tag);
    }
}
           

可以看出我們設計的請求器其實就是Volley裡的一個請求隊列對象而已.

因為使用的是ClassLoader設計方式 因為對象被标記為static

于是在我們RequestManager被加載的時候對象也會被加載存放在類庫裡.

而當程式編譯運作時虛拟機首先加載系統庫的類在加載使用者自定義的庫.

Gson 分析json 的工具包  詳解

StaggeredGridView 詳解

SwipeRefreshLayout 向下拉重新整理  詳解