无法弄清楚为什么AsyncTask中的doInBackground不会覆盖AsyncTask类中的抽象方法

时间:2016-12-01 18:51:52

标签: android android-asynctask

我尝试删除文件而不允许用户进一步输入应用程序,这就是我在删除时使用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 AndroidHow can you pass multiple primitive parameters to AsyncTask?

但是,我仍然收到以下错误: EpgActionProcessor.DeletePartialRecordingTask不是抽象的,并且不会覆盖AsyncTask中的抽象方法doInBackground(DeleteRecordingParams ...)

0 个答案:

没有答案