private Progress createAndShowProgress(final Runnable taskCancelAction) {
        final Progress progress = new Progress();
        if (allowCancel) {
            progress.setOnCancelListener((dialog, which) -> {
                if (allowCloseWithoutCancel) {
                    taskCancelAction.run();
                }
            });
        }
        if (allowCloseWithoutCancel) {
            progress.setOnCloseListener((dialog, which) -> dialog.dismiss());
        }
        progress.setOnDismissListener(d -> {
            if (!allowCloseWithoutCancel) {
                taskCancelAction.run();
            }
        });


        progress.show(activity, title == null ? "" : title, initialMessage == null ? "" : initialMessage, indeterminate, null);
        if (!indeterminate) {
            progress.setMaxProgressAndReset(Math.max(0, maxValue));
        }

        return progress;
    }
Feature to surround execution of a worker task visually with a progress dialog
main/src/main/java/cgeo/geocaching/utils/workertask/ProgressDialogFeature.java