2013-05-07 2 views
0

나는 여러 URL에서 데이터를 추출하고 문자열의 arraylist로 저장하는 안드로이드 애플리케이션이있다. 그것은 잘 작동하지만 13 개의 URL에서 데이터를 가져 오는 데 15-20 초 가까이 걸립니다. 동일한 URL 집합의 데이터를 가져 오는 데는 phonegap을 사용하여 동일한 앱에서 3-4 초가 걸립니다. 아래 코드는 다음과 같습니다.서버에서 데이터를 추출하는 데 너무 많은 시간이 걸린다. - android

 @Override 
     protected String doInBackground(String... params) { 
      client = new DefaultHttpClient(); 
      for(int i=0;i<url.size();i++) 
      { 
       get = new HttpGet(url.get(i)); 
       try { 
        response = client.execute(get); 
       } catch (ClientProtocolException e) { 
        e.printStackTrace(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       entity = response.getEntity(); 
       InputStream is = null; 
       try { 
        is = entity.getContent(); 
       } catch (IllegalStateException e) {   
        e.printStackTrace(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       BufferedReader reader = new BufferedReader(
         new InputStreamReader(is)); 
       StringBuffer buffer = new StringBuffer(); 
       String line = null; 
       do { 
        try { 
         line = reader.readLine(); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
        buffer.append(line); 
       } while (line != null); 
       String str = buffer.toString(); 
       param.add(str);    
      } 
      return null; 
     } 

누구든지이 실행 속도를 높이고 추출 시간을 줄일 수있는 방법을 제안 할 수 있습니까?

+0

병렬 실행을 할 수있는 ... 앱이 안드로이드 API 수준에서 실행되는 무엇이 HttpURLConnection의 클래스 – Prachi

+0

를 사용할 수 있습니까? – TactMayers

+0

@tactmayers, 사용 14! – bharath

답변

0

for 루프에서 반복 할 때마다 별도의 스레드를 시작할 수 있습니다. 이 같은 떨어지게 :

for(int i = 0; i < url.size(); i++){ 
    //start thread that gets data from url and adds it to the list 
} 
관련 문제