如何在android中从缓存中检索图像
以下是代码片段:如何在android中从缓存中检索图像,android,Android,以下是代码片段: private static Drawable getDrawableFromUrl(final String url) throws IOException, MalformedURLException { URL uurl = new URL(url); URLConnection connection = uurl.openConnection(); connection.setUseCaches(true); //sha
private static Drawable getDrawableFromUrl(final String url) throws IOException, MalformedURLException {
URL uurl = new URL(url);
URLConnection connection = uurl.openConnection();
connection.setUseCaches(true); //share cache with browser
Object response = connection.getContent();
return Drawable.createFromStream(((InputStream)response), uurl.getFile());
}
那么现在我如何在下次和以后的时间从缓存中检索它呢?
setUseCaches
并不意味着位图被缓存在某个地方。。。它只是控制此连接是否允许使用缓存
如果您想对位图使用缓存,我强烈建议您使用库