我尝试删除文件而不允许用户进一步输入应用程序,这就是我在删除时使用AsyncTask显示进程对话框的原因。我有以下代码:
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;
}
}
}
我一直关注这两个帖子的实施: How to use AsyncTask correctly in Android和How can you pass multiple primitive parameters to AsyncTask?
但是,我仍然收到以下错误: EpgActionProcessor.DeletePartialRecordingTask不是抽象的,并且不会覆盖AsyncTask中的抽象方法doInBackground(DeleteRecordingParams ...)