I'm trying to delete a file without allowing the user to make further input to the application which is why I'm using an AsyncTask to show a Process Dialog while the delete occurs. I have the following code:
public class EpgActionProcessor {
private final Logger logger;
private final IAdrAccountManager accountManager;
private ProgressDialogFragment fragment;
private MiddlewareAsyncOperationProcessor<EpgDeleterWorkItem> processorDeleteItem;
private MiddlewareAsyncOperationProcessor<EpgScheduleWorkItem> processorScheduleItem;
@Inject
public EpgActionProcessor(Logger logger, IAdrAccountManager accountManager) {
this.logger = logger;
this.accountManager = accountManager;
}
public boolean deleteRecording(ActivityBase activity, EpgBrowserCurrentItem epgCurrent, AsyncOperationListener<EpgDeleterWorkItem>
asyncOperationListener) {
Opt<EpgProgramInfo> info = epgCurrent.getEpgProgramInfo();
if (!info.isPresent()) {
return false;
}
DeleteRecordingParams params = new DeleteRecordingParams(info, activity, asyncOperationListener);
DeletePartialRecordingTask task = new DeletePartialRecordingTask(params);
task.execute(params);
return true;
}
private class DeletePartialRecordingTask extends AsyncTask<DeleteRecordingParams,Void,Void> {
private Opt<EpgProgramInfo> info;
private ActivityBase activityBase;
private AsyncOperationListener asyncOperationListener;
DeletePartialRecordingTask(DeleteRecordingParams deleteRecordingParams){
this.info = deleteRecordingParams.info;
this.activityBase = deleteRecordingParams.activity;
this.asyncOperationListener = deleteRecordingParams.asyncOperationListener;
}
@Override
protected void onPreExecute() {
// Show dialog indicating that content is being deleted
if(fragment == null){
fragment = (ProgressDialogFragment) activityBase.getSupportFragmentManager().findFragmentByTag(ProgressDialogFragment.class
.getSimpleName());
}
if (fragment != null) {
fragment.setTitle("Deleting content...");
}
}
@Override
protected Void doInBackground(DeleteRecordingParams params) {
//Delete
CMwEpgProgramDeleteScheduledWorkerEnabler enabler = info.get().getScheduledRecordingDeleter();
IMwEpgProgramDeleteScheduledWorker worker = enabler.getWorkItem();
worker.shouldDeletePartialRecording(true);
processorDeleteItem = new MiddlewareAsyncOperationProcessor<EpgDeleterWorkItem>(
new EpgDeleterWorkItem(worker),
accountManager,
asyncOperationListener,
logger);
processorDeleteItem.start();
enabler.enable();
return null;
}
@Override
protected void onPostExecute(Void result){
super.onPostExecute(result);
fragment.dismiss();
fragment = null;
}
}
private static class DeleteRecordingParams {
Opt<EpgProgramInfo> info;
ActivityBase activity;
AsyncOperationListener asyncOperationListener;
DeleteRecordingParams(Opt<EpgProgramInfo> info, ActivityBase activity, AsyncOperationListener asyncOperationListener){
this.info = info;
this.activity = activity;
this.asyncOperationListener = asyncOperationListener;
}
}
}
I've been following the implementations from these two posts: How to use AsyncTask correctly in Android and How can you pass multiple primitive parameters to AsyncTask?
However, I am still getting the following error: EpgActionProcessor.DeletePartialRecordingTask is not abstract and does not override abstract method doInBackground(DeleteRecordingParams...) in AsyncTask