public void setupTask(Task asyncTask) {
   // Keep task
   mAsyncTask = asyncTask;
   // Wire task to tracker (this)
   mAsyncTask.setProgressTracker(this);
   // Start task
   mAsyncTask.execute();
 }
  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);
  }
  public Object retainTask() {
    // Close progress dialog
    mProgressDialog.cancel();

    // Detach task from tracker (this) before retain
    if (mAsyncTask != null) {
      mAsyncTask.setProgressTracker(null);
    }
    // Retain task
    return mAsyncTask;
  }
 @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 onTaskComplete(Task task) {
   if (task != null && !task.isCancelled()) {
     if (task instanceof AsyncCommand) {
       AsyncCommand t = (AsyncCommand) task;
       if (t.isSuccess()) {
         setListAdapter();
       } else {
         Exception e = t.getException();
         ExceptionHelper.onException(e, this, TAG);
       }
     }
   }
 }
  @Override
  public void onProgress(String message) {
    if (mAsyncTask.isHidden()) {
      return;
    }

    Context context = weakContext.get();
    if (context == null) {
      return;
    }

    // Show dialog if it wasn't shown yet or was removed on configuration
    // (rotation) change
    try {
      if (!mProgressDialog.isShowing()) {
        mProgressDialog.show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    // Show current message in progress dialog
    mProgressDialog.setMessage(message);
  }
 @Override
 protected void onPostExecute(Boolean result) {
   super.onPostExecute(result);
 }