Android.app.ProgressDialog
lastmod 2018-08-17created 2016-06-301 edits
A dialog showing a progress indicator and an optional text message or view. Only a text message or a view can be used at the same time. The dialog can be made cancelable on back key press.
The progress range is 0..10000.
Example of handling Cancel on Android
The code below is an example that handles cancellation in an AsyncTask when the ProgressDialog's cancel button is clicked.
class MyTask extends AsyncTask<Void, Void, Void> {
private volatile boolean running = true;
private final ProgressDialog progressDialog = null;
public MyTask(Context ctx) {
// progressDialog = gimmeOne(ctx);
progressDialog.setCancelable(true);
progressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// actually could set running = false; right here, but I'll
// stick to contract.
cancel(true);
}
});
}
@Override
protected void onPreExecute() {
progressDialog.show();
}
@Override
protected void onCancelled() {
running = false;
}
@Override
protected Void doInBackground(Void... params) {
while (running) {
// does the hard work
}
return null;
}
// ...
}
See also
Favorite site
- Android Dialogs
- Android ProgressDialog
- Android ProgressBar and ProgressDialog
- How to show download progress with a progress bar when receiving a file on Android
- Android: Dialog, AlertDialog, ProgressDialog, DatePickerDialog, TimePickerDialog
- [Recommended] Download a file with Android, and showing the progress in a ProgressDialog 1
- Blocking hardware Keys in Dialog and ProgressDialog
References
-
Android_download_progress.pdf ↩