我不知道为什么我的代码不工作。我读了很多相同的问题,但这在大多数情况下都是正确的解决方案,但对我而言并不奏效。我的AsyncTask看起来是这样的:我不能用方法dismiss()停止ProgressDialog;
public class SavingAsync extends AsyncTask<String, String, String> {
private static final String TAG = "DrawView";
private ProgressDialog pd;
private Context context;
private File saveFile;
private Bitmap bitmap;
public SavingAsync(Context c, File sF, Bitmap b) {
context = c;
saveFile = sF;
bitmap = b;
}
@Override
protected void onPostExecute(String result) {
pd.dismiss();
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
pd = new ProgressDialog(context);
ProgressDialog.show(context, "", "Saving...");
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
OutputStream stream;
try {
stream = new FileOutputStream(saveFile);
bitmap.compress(CompressFormat.PNG, 80, stream);
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
位图被成功地保住了,但ProgressDialog永远运行:/
请查看http://developer.android.com/reference/android/app/DialogFragment.html – 2012-07-20 00:09:55