2013-10-16 3 views
1

내 애플리케이션에서 HttpRequest를 여러 번 사용하고 있습니다. 매번 휴식을 요청하지 않는 방법이 있습니까?Android httpRequest 캐싱

즉 API 요청 캐시의 캐시 유지 방법. 인터넷이없는 경우에도 작업해야합니다.

미리 감사드립니다.

+1

https://developers.google.com를 읽을 수 있습니다/events/io/sessions/325304728 답변은 발리입니다. – Reinherd

+0

Thnak you Sergi Castellsagué Millán, 발리는 최고의 대답입니다. 예제 코드는 http://arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/에 있습니다. –

답변

3

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