title: RawPushNotification when app not running Windows Phone 8.1
body: <p>I have been trying to write Background Task that would show raw push notification as toast. I got push notifications working when app is running.</p>
  
  <p>This is my background task class:</p>
  
  <pre><code>public sealed class BackgroundNotificationsTask : IBackgroundTask
  {
  
      public void Run(IBackgroundTaskInstance taskInstance)
      {
          RawNotification notification = (RawNotification)taskInstance.TriggerDetails;
          string content = notification.Content;
  
          Debug.WriteLine("Background raw notification obtained!");
  
          //SendNotification(content);
      }
  
      private void SendNotification(string text)
      {
          XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
  
          XmlNodeList elements = toastXml.GetElementsByTagName("text");
          foreach (IXmlNode node in elements)
          {
              node.InnerText = text;
          }
  
          ToastNotification notification = new ToastNotification(toastXml);
          ToastNotificationManager.CreateToastNotifier().Show(notification);
      }
  
  }
  </code></pre>
  
  <p>Then I Register In MainPage.xaml.cs</p>
  
  <pre><code>    private void RegisterTasks()
      {
          BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
  
          var taskRegistered = false;
          var exampleTaskName = "NotificationsBackground";
  
          foreach (var task in BackgroundTaskRegistration.AllTasks)
          {
              if (task.Value.Name == exampleTaskName)
              {
                  taskRegistered = true;
                  break;
              }
          }
  
          if(!taskRegistered)
          {
              var builder = new BackgroundTaskBuilder();
  
              builder.Name = exampleTaskName;
              builder.TaskEntryPoint = "BackgroundTasks.NotificationsBackground";
              builder.SetTrigger(new Windows.ApplicationModel.Background.PushNotificationTrigger());
  
              try
              {
                  BackgroundTaskRegistration task = builder.Register();
  
                  Debug.WriteLine("Background Task registered.");
              }
              catch (Exception e)
              {
                  Debug.WriteLine("Background Task register exception: " + e.ToString());
              }
          }
      }
  </code></pre>
  
  <p>Now in appxmanifest I have set 'Lock screen notifications' to Badge, then in  Declarations I have added Background Task with properies Push notification selected and entry point set as BackgroundNotificationsTask.cs</p>
  
  <p>![screen][2]</p>
  
  <p>Am I doing something wron or is there something that I am missing?</p>
  
  <p>EDIT:</p>
  
  <p>Right now when i obtain push notification the app closes... anyone know why?</p>
  
  <p><img src="https://i.stack.imgur.com/CN2gr.png" alt="hah"></p>