似乎這個類不工作,因爲它從不發佈進度。 onPostExecute
實際工作。但這個班主要依靠progressUpdate
。AsyncTask不能在onProgressUpdate Android
class DoBackgroundStuff extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... a) {
String rawContactsDl;
while(true) {
if (isFinished == true) {
backgroundStopped = true;
break;
}
//DO SOME STUFF
publishProgress(1);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return "done";
}
protected void onProgressUpdate(int progress) {
Log.i("VERBOSE","onProgress " + progress);
adapter.notifyDataSetChanged();
}
protected void onPostExecute(String result) {
Log.i("VERBOSE","onPosts " + result);
adapter.notifyDataSetChanged();
}
}
isFinished ==是真的嗎? – ElDuderino
哦,男人!無限循環 –