2014-04-09 2 views
0

입니다.이 코드는 이미지를 다운로드 할 때 사용하는 코드입니다.이 코드를 최적화하여 각 이미지의 다운로드 시간을 줄이는 방법을 알려줄 수 있습니까?다운로드 시간이

 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(); 
       } 
      } 

     } 
+0

최신 버전에서는 기본 UI 스레드에서 수행 할 수 없으므로 AsyncTask를 사용해야합니다. – Nepster

답변

1

나는 또한 OrhancC1 그것에 나를 이길 때 피카소을 제안 바쁜주세요, 그래서 당신이 사용하게한다면 그를 신용.

피카소는 좋습니다! 우리는이 프로젝트를 프로젝트 중 하나에서 사용하고 HTTP 캐싱이 올바르게 작동하도록 관리했습니다. 우리의 응용 프로그램에서 우리가 다운로드하는 이미지는 자주 변경되지 않으므로 네트워크에서 가장 빠르게 처리되는 캐시에서 이후의 모든로드가 처음으로로드되면로드됩니다.

옵션이 아닌 이유가 무엇이든이 질문에 대한 답변은 관련성이 있습니다 (Speed Up download time).