【发布时间】:2015-12-07 06:59:44
【问题描述】:
遇到从我的网络服务器加载个人资料图片所需时间过长的问题。这是我用来加载图像的代码(在 AsyncTask 中):
@Override
protected Bitmap doInBackground(Void... params) {
String urlPath = AppVariables.SERVER_ADDRESS + "pictures/" + name + ".JPG";
try {
URLConnection connection = new URL(urlPath).openConnection();
connection.setUseCaches(true);
connection.setConnectTimeout(1000 * 30);
connection.setReadTimeout(1000 * 30);
return BitmapFactory.decodeStream((InputStream) connection.getContent(), null, null);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
这应该根据这里的最佳答案工作:Android image caching
但我仍然遇到延迟 - 当我转到应用程序中的“个人资料”时,需要 2-3 秒才能显示个人资料图片。
有什么想法吗?
【问题讨论】:
标签: android database caching bitmap