我不知道爲什麼我的代碼不工作。我讀了很多相同的問題,但這在大多數情況下都是正確的解決方案,但對我而言並不奏效。我的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