即使我的progressdialog有问题(现在),当我的异步线程onProgressUpdate()永远不会被调用时,它都会停止。 onPreExecute()和doInBackground()运行得很好,但我不能为我的生活得到onProgressUpdate()函数启动:( 代码主要取自她:http://developer.android.com/reference/android/os/AsyncTask.html
这是我的代码版本:
private class createPasswordList2 extends AsyncTask<String, Integer, Long> {
@Override
protected void onPreExecute() {
super.onPreExecute();
Log.v(logtag,"In async: onPreExecute...");
//ProgressDialog progressDialog = ProgressDialog.show(MainActivity.this, "Wait", "Downloading...");
//pDialog = new ProgressDialog(context);
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Decrypting, Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Long doInBackground(String... foo) {
int count =20;
long totalSize = 0;
for (int i = 0; i < count; i++) {
try{
Thread.sleep(1000);
}catch(Exception e) {
Log.v(logtag, e.getMessage());
}
totalSize +=1;
Log.v(logtag,"async2...doInBackground");
publishProgress((int) ((i / (float) count) * 100));
// Escape early if cancel() is called
if (isCancelled()) break;
}
return totalSize;
}
@Override
protected void onProgressUpdate(Integer... progress) {
String logtag="";
Log.v(logtag,"async2...onProgressUpdate");
pDialog.setProgress(progress[0]);
}
@Override
protected void onPostExecute(Long result) {
Log.v(logtag,"async2...onPostExecute");
pDialog.dismiss();
// showDialog("Downloaded " + result + " bytes");
}
}
程序执行doInBackground()函数并打印日志行,但手机屏幕变黑并且永不改变。我已经为我的问题搜索了整个(我确定...)互联网,但是所提出的解决方案似乎都不起作用。
任何和所有帮助appriciated
午