웹 서버의 응답으로 특정 날짜의 데이터를 가져 오는 응용 프로그램이 있으며 데이터 (숫자/시간)에 따라 o/p 그래프를 플로팅합니다.android async tasks
지금은 웹 서버를 비동기 작업으로 호출하고 있습니다.
웹 서버를 여러 번 호출하여 여러 개의 비동기 작업을 수행하여 서버에서 데이터를 가져올 수도 있습니다 (전날/익일).
문제는 flings (비동기 작업)의 수가 증가하여 응용 프로그램에 ANR이 표시되는 경우입니다.
각 웹 서버 호출 (fling)마다 비동기 작업을 생성하는 대신 이러한 종류의 시나리오를 처리하는 더 좋은 방법이 있습니까? 코드의
추가 부분 :
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
valuesDayWithTime=onStart(datePrevious);
}
public GraphView onStart(String date){
urlFinal=createUrl();
new DownloadDataTask(this).execute(urlFinal);
}
private class DownloadDataTask extends AsyncTask<String, Integer, Long> {
YieldActivity yActivity;
ProgressBar pBar ;
DownloadDataTask(YieldActivity act){
yActivity=act;
}
protected void onPreExecute() {
relLay=(RelativeLayout) findViewById(R.id.graphView);
pBar
= new ProgressBar(yActivity);
LayoutParams lp =new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
pBar.setLayoutParams(lp);
pBar.setMax(100);
relLay.removeAllViews();
relLay.addView(pBar);
}
protected Long doInBackground(String... urls) {
int totalCount = urls.length;
for (int i = 0; i < totalCount; i++) {
publishProgress((int) ((i/(float) totalCount) * 100));
downloadFromUrl(urls[i]);
}
return (long) totalCount;
}
protected void onProgressUpdate(Integer... progress) {
Log.i(progress[0] +"%");
}
protected void onPostExecute(Long result) {
graphViewDay=calculate(dateNow,valuesDayWithTime);
relLay.removeView(pBar);
relLay.addView(graphViewDay);
}
}
public void downloadFromUrl(String fromURL) {
try {
getHttpResponse(fromURL.toString());
parseResponse();
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
다른 사람들이 참조 할 수 있도록 나와있는 솔루션을 게시하십시오. –