@Override
    public void accept(final WorkerTask<?, ? extends P, ?> task) {

        final Progress[] progressStore = new Progress[1];

        task.observe(activity, event -> {
            Log.d("WORKERTASK:PROGRESSDIALOG (progress = " + (progressStore[0] != null) + ": received " + event);

            switch (event.type) {
                case STARTED:
                    if (progressStore[0] == null) {
                        progressStore[0] = createAndShowProgress(task::cancel);
                    }
                    break;
                case PROGRESS:
                    if (progressStore[0] == null) {
                        progressStore[0] = createAndShowProgress(task::cancel);
                    }
                    setProgress(progressStore[0], event.progress);
                    break;
                default:
                    cancelProgress(progressStore[0]);
                    progressStore[0] = null;
                    break;
            }
        });
    }
Feature to surround execution of a worker task visually with a progress dialog
main/src/main/java/cgeo/geocaching/utils/workertask/ProgressDialogFeature.java