Volley 加載圖片內存溢出解決辦法

咱們要保持項目中惟一一個Volley的RequestQueue,使用單例模式來實現
public class NetRequest {spa

    private static RequestQueue mQueue = null;
    private static Lock lock = new ReentrantLock();
    private static final String NETREQUEST = "netrequest";
    
    public static RequestQueue getInstance(Context context) {
        if (mQueue == null) {
            lock.lock();
            if (mQueue == null) {
                mQueue = Volley.newRequestQueue(context.getApplicationContext());
            }
            lock.unlock();
        }
        return mQueue;
    }
}get

相關文章
相關標籤/搜索