title: AsyncTask to run on Activity start fails after previously getting cancelled
body: <p>I am using an AsyncTask to fetch the ring tone for a contact when my application starts, it works fine until after my Activity closes a couple of times during the AsyncTask, after this happens the AsyncTask will only ever get to onPreExecute() and never doInBackground, so I can never fetch the ringtone then until either a force stop or device restart.</p>
  
  <p>Can anyone explain why this might be happening?</p>
  
  <p>Why the AsyncTask would get to onPreExecute but then never run doInBackground()?</p>
  
  <p>Here is my code: (Following the Shelves source code)</p>
  
  <pre><code>public void getRingTone(){
  Log.d("cda", "Into getRingTone");  
  if (audio_service.getStreamVolume(AudioManager.STREAM_RING) &gt; 0) { 
      if(aRingTone != null){ 
          oRingtone = RingtoneManager.getRingtone(this, 
                Uri.parse(aRingTone));
      }
      this.setVolumeControlStream(AudioManager.STREAM_RING);
  
   }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>private void saveRingToneTask(Bundle outState) {
  final SelectRingtoneTask task = srtt;
  if (task != null &amp;&amp; task.getStatus() != AsyncTask.Status.FINISHED) {
      task.cancel(true);
  
      srtt = null;
  }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>private void restoreRingToneTask(Bundle savedInstanceState) {
  
          srtt = (SelectRingtoneTask) new SelectRingtoneTask().execute();
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>private void onAddRingTone() {
  srtt = (SelectRingtoneTask) new SelectRingtoneTask().execute();
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>private void onCancelAddRingTone() {
  if (srtt != null &amp;&amp; srtt.getStatus() == AsyncTask.Status.RUNNING) {
      srtt.cancel(true);
      srtt = null;
  }
  }
  </code></pre>
  
  <p>--</p>
  
  <pre><code>@Override
  protected void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);
  restoreRingToneTask(savedInstanceState);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Override
  protected void onSaveInstanceState(Bundle outState) {
  super.onSaveInstanceState(outState);
  if (isFinishing()) {
      saveRingToneTask(outState);
  }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>private class SelectRingtoneTask extends AsyncTask&lt;String, Void, Void&gt; {
  
  
  @Override
  public void onPreExecute() {
      Log.d("cda", "Into selectRingToneTask - onPreExecute() - " + selectRingtoneFinished);
      findViewById(R.id.answercallimage).setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
              try {
                      serviceBinder.answer(lineId);
                      onCancelAddRingTone();
                  } catch (RemoteException e) {
  
                      e.printStackTrace();
                  }
          }
  });
  
  
      findViewById(R.id.declinecallimage).setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
  
              mNotificationManager.cancel(2);
              callConnected = false;
  
              try {
                  serviceBinder.reject(lineId);
                  onCancelAddRingTone();
              } catch (RemoteException e) {
  
                  e.printStackTrace();
              }
          }
  });
  
  }
  
  
  
  public Void doInBackground(String... params) {
      Log.d("cda", "Into selectRingToneTask - !!!!!!!!!!!!!!!");
      if(!this.isCancelled()){
      getRingTone();
      }
      return null;
  
  }
  
  @Override
  public void onCancelled() {
      Log.d("cda", "Into selectRingToneTask - onCancelled() - ");
  }
  
  @Override
  public void onPostExecute(final Void unused) {
       selectRingtoneFinished = true;
         Log.d("cda", "Into selectRingToneTask - onPostExecute - " + selectRingtoneFinished);
         if(oRingtone != null &amp;&amp; playRingTone){
              Log.d("cda", "Into getRingTone - PLAY RINGTONE");  
             oRingtone.play();
          }
  }
  }
  </code></pre>
  
  <hr>
  
  <p>And onAddRingtone() is used in onCreate and onCancelRingTone() is used in onDestroy() as well as where you can see if in the code above.</p>
  
  <p>I have spent 3 days on this and I haven't been able to find a solution? Am I taking the wrong approach? Using cancel wrong? Is there a bug?</p>