Issues and contribution for Volley [closed]

拜拜、爱过 提交于 2019-12-02 16:14:46

Seems like a lot has been answered in the comments but I'll try to cover the rest, or rather, I'll try to cover your specific questions.

1) Volley does not handle redirection on it's own. It's handled by the underlying HttpStack. For example, I currently use OkHttp (from Square) as my HTTP client for Volley. See https://plus.google.com/108284392618554783657/posts/eJJxhkTQ4yU https://gist.github.com/JakeWharton/5616899 OkHttp is great, as it has excellent defaults for handling SPDY, redirects, and other HTTP conveniences. You could also use this to implement your own defaults for the platform HttpUrlConnection (calling followRedirects() on the connection before handing it to Volley for example --- https://developer.android.com/reference/java/net/HttpURLConnection.html#setFollowRedirects(boolean))

2) I'm not even sure that I'd use getCacheDir() for a Volley cache. According to the docs (https://developer.android.com/reference/android/content/Context.html#getCacheDir()), that cache directory should never exceed 1 mb. Whereas, most clients tend to use 10 mb as a default for an http cache (1 mb is really small for an Http cache!!). Also, why are you using such a deep cache directory? Theres no reason that "cacheDir1" should be multiple directories deep. Just make it a file name. getCacheDir() would return your own folder anyways. I'd recommend doing this when initializing Volley (usually the recommended place is the Application class):

File volleyCacheFile = new File(getExternalCacheDir(), "volleyCache.tmp");

Of course, this lacks any error handling (what if the external storage is unavailable?). Also, don't forget that you need the appropriate permission to write the external storage.

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!