title: BackgroundAudioTask not working after cancelled by another app
body: <p>When the <code>BackgroundAudioTask</code> for my app is cancelled by other app on Windows Phone 8.1 which also uses <code>BackgroundAudioTask</code>, when I go back into my app, it will no longer play audio in the background. It will play fine when the app is running but if it is suspended - the background audio also stops. </p>
  
  <p>The steps to reproduce this issue are:<br>
  I launch the Windows Phone 8.1 app which has a <code>BackgroundAudioTask</code> &amp; everything works fine. I that start another app, for example the Music player, that uses a <code>BackgroundAudioTask</code> it will cancel the <code>BackgroundAudioTask</code> of my app. </p>
  
  <p>When I launch my app for the second time, I want to re-register my <code>BackgroundAudioTask</code> so that it will behave as it did originally.</p>
  
  <p>In <strong>Package.appxmanifest</strong> I have the following:</p>
  
  <pre><code>&lt;Extensions&gt;
      &lt;Extension Category="windows.backgroundTasks" EntryPoint="WindowsPhoneBackgroundAudioTask.BackgroundAudioTask"&gt;
        &lt;BackgroundTasks&gt;
          &lt;Task Type="audio" /&gt;
        &lt;/BackgroundTasks&gt;
      &lt;/Extension&gt;
    &lt;/Extensions&gt;
  </code></pre>
  
  <p>When I first run the application the <strong>Run</strong> method will be called and I add a <strong>Deferral</strong> to the task to make sure it is kept alive even when I close my application:</p>
  
  <pre><code>public void Run(IBackgroundTaskInstance taskInstance)
  {
      setupDeferral = taskInstance.GetDeferral();
  } 
  </code></pre>
  
  <p>When I start the music player from another application my BackgroundAudioTask <strong>Cancelled</strong> event is called (If I don't do <code>setupDeferral.Complete()</code> here my application will crash):</p>
  
  <pre><code>private void Task_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
  {
      setupDeferral.Complete();
  }
  </code></pre>
  
  <p>When I open my app how do I recreate my <code>BackgroundAudioTask</code>? The problem is the <code>Run</code> method is never called again so I can't setup the <code>Deferral</code> again. Music will now play fine in the app, but as soon as I navigate away from the app the music will stop. </p>
  
  <p>I tried manually <strong>re-registering the task</strong> in App.xaml.cs in the App_Resuming event with this code:</p>
  
  <pre><code>var taskBuilder = new BackgroundTaskBuilder();
  taskBuilder.Name = "BackgroundAudioTask";
  taskBuilder.TaskEntryPoint = typeof(WindowsPhoneBackgroundAudioTask.BackgroundAudioTask).FullName;
  BackgroundTaskRegistration task = taskBuilder.Register();
  </code></pre>
  
  <p>The above code will throw and <code>InvalidArgumentException</code> because it does not have a Trigger setup.  I don't want it to have a trigger. I just want to start the background task immediately.</p>
  
  <p>Is there a way to manually instruct the OS to run the background audio again or a way to handle cancelled background audio better?</p>