我的应用程序多次使用HttpRequest。有没有办法不在每次都调用Rest?
即如何为Api请求调用维护高速缓存。而且它也应该在没有互联网的情况下工作
提前谢谢。
发布于 2013-10-16 23:01:44
Android有自己的类来缓存响应。要打开缓存,您应该调用HttpResponseCache.install方法。比如
HttpResponseCache.install(getCacheDir(), 10 * 1024 * 1024); //10MB cache size当你打开连接调用时
connection.setUseCaches(true);像这样的东西
URL url = new URL("http://site.com/");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setUseCaches(true);你也可以阅读这个topic
https://stackoverflow.com/questions/19406556
复制相似问题