I don’t know why my code not working. I read a lot of same problems, but this is in most cases right solution, but for me is not working. My AsyncTask looks like this:
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;
}
}
Bitmap is saved sucessfully, but ProgressDialog run forever :/
You are showing ProgressDiaog with
and show method returns a PreogressDialog object.
The dialog you are dismissing using
pdreference variable using pd.dismiss()in your code does to have reference to dialog you are showing. You should assign it topd. Like thisAnd then calling
pd.dismiss()will dismiss the currently showingDialog.