title: Canceling AsyncTask that is not running Calls onCancelled?
body: <p>I have an Asynctask B that is executed from activity A.
  On post execute of that B, on a certain condition B might create a new instance of itself and execute it.</p>
  
  <p>What i did is put the AsyncTask declaration as global inside the B and overridden the onCancelled of B to cancel the new instance that is created onpostexecute.</p>
  
  <p>so onDestroy of Activity A b.cancel() will also cancel the any AsyncTask executed onPostExecute.</p>
  
  <pre><code>  @Override
     protected void onCancelled()
     {
        if(currentPlansAsync != null)
        {
           currentPlansAsync.cancel(true);
        }
        super.onCancelled();
     }
  </code></pre>
  
  <p>And new instance of currentPlansAsync is called onPostExecute as follows:</p>
  
  <pre><code> private void processAfterFailure()
     {
  
        if(this.counter &lt; 3)
        {
           ProgressDialog progressDialog =
              GeneralUtils.showProgressDialog(parentActivity, parentActivity.getResources().getString(string.WaitDialogTitle),
                 parentActivity.getResources().getString(string.WaitDialogMessage));
           this.counter++;
           currentPlansAsync = new CurrentPlansAsync(parentActivity, application, progressDialog, application.planBL, this.counter);
           currentPlansAsync.execute();
  
        }
        else
        {
           Toast.makeText(parentActivity, parentActivity.getResources().getString(string.SERVICE_ERROR), Toast.LENGTH_LONG).show();
        }
  
     }
  </code></pre>
  
  <p><strong>My question is that if AsyncTask B has stopped execution and it has executed another asynctask C and activity A goes to onDestroy and B is cancelled ( <code>b.cancel(true);</code>)
  will onCancelled that is overridden in class B be called ??</strong> </p>
  
  <p><em><strong>This is so i ensure that i cancel the AsyncTask that was executed from the activity and also the AsyncTask executed from within that AsyncTask</em></strong></p>