입니다.이 코드는 이미지를 다운로드 할 때 사용하는 코드입니다.이 코드를 최적화하여 각 이미지의 다운로드 시간을 줄이는 방법을 알려줄 수 있습니까?다운로드 시간이
URL url;
HttpURLConnection connection = null;
InputStream input = null;
System.setProperty("http.keepAlive", "true");
try {
url = new URL(urlString);
connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(HTTP_CONNECTION_TIMEOUT);
connection.setRequestProperty("Connection", "Keep-Alive");
input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
currentRequestInProgress.remove(urlString);
if (connection != null)
connection.disconnect();
if(input != null){
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
최신 버전에서는 기본 UI 스레드에서 수행 할 수 없으므로 AsyncTask를 사용해야합니다. – Nepster