我试图在加载一些信息时将 ProgressDialog 放入 AsyncTask 并旋转。问题是它启动良好,但突然停止旋转,一瞬间,该应用程序似乎不再工作了。旋转只是获取堆栈,直到加载所有信息时它消失并且信息正确显示。这是我正在使用的 AsyncTask:
public class LoadCarsTask extends AsyncTask<String, Car, List<Car>>{
private SearchFragmentActivity sma;
private ListFragment fragment;
public LoadCarsTask (ListFragment fragment){
this.fragment = fragment;
dialog = new ProgressDialog(fragment.getActivity());
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
adapter = new SearchCarListAdapter(SearchCarListActivity.this.getActivity(), showedCars, showedDistance, showedReviews, showedPhotos);
dialog.setMessage("Finding Cars...");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.show();
}
public SearchFragmentActivity getSma() {
return sma;
}
public void setSma(SearchFragmentActivity sma) {
this.sma = sma;
}
@Override
protected List<Car> doInBackground(String... params) {
maxPerHour = Double.parseDouble(filterparams[0]);
maxPerKm = Double.parseDouble(filterparams[1]);
maxDistance = Double.parseDouble(filterparams[2]);
longitude = Double.parseDouble(filterparams[3]);
latitude = Double.parseDouble(filterparams[4]);
URL url;
try {
//A long calculation goes here
return cars;
}
@Override
protected void onProgressUpdate(Car... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(List<Car> result) {
super.onPostExecute(result);
SearchFragmentActivity.setCars(cars);
sfa.setUpDistances();
distance = SearchFragmentActivity.getDistances();
setUpReviews();
setUpPhotos();
while (carsCount<carsNumber && carsCount<cars.size()){
showedCars.add(cars.get(carsCount));
showedDistance.add(distance.get(carsCount));
showedPhotos.add(photos.get(carsCount));
showedReviews.add(reviews.get(carsCount));
carsCount++;
}
adapter = new SearchCarListAdapter(SearchCarListActivity.this.getActivity(), showedCars, showedDistance, showedReviews, showedPhotos);
adapter.setCurrentLocation(loc);
setListAdapter(adapter);
if(dialog.isShowing())
dialog.dismiss();
//sma.showAvailableCarsOnMap();
}
}
}