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;
}
누구든지이 실행 속도를 높이고 추출 시간을 줄일 수있는 방법을 제안 할 수 있습니까?
병렬 실행을 할 수있는 ... 앱이 안드로이드 API 수준에서 실행되는 무엇이 HttpURLConnection의 클래스 – Prachi
를 사용할 수 있습니까? – TactMayers
@tactmayers, 사용 14! – bharath