public void handleRetainedTask(Task task, OnTaskCompleteListener taskCompleteListener) {
    this.taskCompleteListener = taskCompleteListener;
    setupProgressDialog(taskCompleteListener.getContext());

    // Restore retained task and attach it to tracker (this)
    mAsyncTask = task;
    mAsyncTask.setProgressTracker(this);
  }
 @Override
 public void onCancel(DialogInterface dialog) {
   if (mAsyncTask == null) {
     return;
   }
   // Cancel task
   mAsyncTask.cancel(true);
   // Notify activity about completion
   taskCompleteListener.onTaskComplete(mAsyncTask);
   // Reset task
   mAsyncTask = null;
 }
  @Override
  public void onComplete() {
    // Close progress dialog
    try {
      mProgressDialog.cancel();
    } catch (IllegalArgumentException e) {
      Logger.e(TAG, "View not attached to window manager");
    }

    // Reset task
    Task completedTask = mAsyncTask;
    mAsyncTask = null;

    // Notify activity about completion
    taskCompleteListener.onTaskComplete(completedTask);
  }
 public AsyncTaskManager(OnTaskCompleteListener taskCompleteListener) {
   this.taskCompleteListener = taskCompleteListener;
   Context context = taskCompleteListener.getContext();
   this.weakContext = new WeakReference<Context>(context);
   setupProgressDialog(context);
 }