小编Xia*_*zou的帖子

使用Volley和OkHttp时如何配置Http Cache?

我想尝试将Volley与OkHttp结合使用,但是Volley缓存系统和OkHttp都依赖于HTTP规范中定义的HTTP缓存.那么如何禁用OkHttp的缓存以保留一份HTTP缓存?

编辑:我做了什么

public class VolleyUtil {
    // http://arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/
    private volatile static RequestQueue sRequestQueue;

    /** get the single instance of RequestQueue **/
    public static RequestQueue getQueue(Context context) {
        if (sRequestQueue == null) {
            synchronized (VolleyUtil.class) {
                if (sRequestQueue == null) {
                    OkHttpClient client = new OkHttpClient();
                    client.networkInterceptors().add(new StethoInterceptor());
                    client.setCache(null);
                    sRequestQueue = Volley.newRequestQueue(context.getApplicationContext(), new OkHttpStack(client));
                    VolleyLog.DEBUG = true;
                }
            }
        }
        return sRequestQueue;
    }
}
Run Code Online (Sandbox Code Playgroud)

OkHttpClient是从引用https://gist.github.com/bryanstern/4e8f1cb5a8e14c202750

android caching android-volley okhttp

20
推荐指数
1
解决办法
1313
查看次数

导航到列表末尾时如何保持RecyclerView的最后一项焦点?

我在电视开发中使用了带有HORIZONTAL方向的RecyclerView,它由D-pad控制,从左到右导航列表.当导航到最右边的列表时,RecyclerView的最后一项始终失去焦点.

那么当导航到列表末尾时,如何保持最后一项的焦点?

android android-tv android-recyclerview

6
推荐指数
1
解决办法
8544
查看次数