Introducing SuspensionManager

A SuspensionManager class exists that can do all this saving and restoring work (and a bit more) for you. It exposes a SessionState property that is the same type of Dictionary used in the previous snippets, as well as similar SaveAsync and RestoreAsync methods.

To use this, you must call RestoreAsync inside OnLaunched for the previously terminated condition:

if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) {   // Restore the saved session state only when appropriate   await SuspensionManager.RestoreAsync(); }

You can set and retrieve session state values as follows:

// Store a value SuspensionManager.SessionState["CurrentIndex" ...

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.