Application Lifecycle

 States

  • Running App
    • Suspending ->
    • <- Resuming
  • Suspended App
    • Low Memory ->
  • Terminated App

Handling Suspension

publc App()
{
  this.InitializeComponent();
  this.Suspending += (s, e) =>
  {
    // Save Data
  };
  
  this.Resuming += (s, e) =>
  {
    // Load Data
  };
}

OnLaunch

  • ClosedByUser
  • Terminated
  • Running
  • Suspended

Navigation

  • Back from Terminated -> Read from File -> Frame.GetNavigationState()
  • Suspended -> Frame.SetNavigationState() -> Save to File

Extended execution

Type 1

  • Suspending
  • No UI
  • Revoked Event after 1 Second

Example

private async void OnSuspending(object sender, SuspendingEventArgs args)
{
  var deferral = e.SuspendingOperation.GetDeferral();
  
  using(var session = new ExtendedExecutinSession{ Reason = ExtendedExecutionReason.SavingData})
  {
    Session.Description = "Upload Data";
    Session.Revoked += (s, e) => { Log("Save incomplete"); };

    try
    {
      if(await session.RequestExtensionAync() == ExtendedExecutionResult.Denied)
        UploadData();   // 3 Seconds Task
      else
        UploadData(session);   // 8 Seconds Task
      
      Log("Save Complete");
    }
    catch { Log("Save failed"); }
    finally { deferral.Complete(); }
  }
}

 

Type 2

  • Request during Runtime
  • No UI
  • Automatic extension

Example

private async void InvokeMyExtension()
{
  if(this._Session == null)
  {
    this._session = new ExtendedExecutinSession () { Reason = ExtendedExecutionReason.LocationTracking})
    this._Session.Description = "Driving Directions";
    
    if(await this._session.RequestExensionAsync() == ExtendedExecutionResult.Allowed)
    {
      // todo approved
    }
    else
    {
      // todo denied
    }

Type 3

  • Burst Event Pool???

Example