This sample shows you how to use the Windows.UI.WebUI.WebUIApplication Activated, Suspending and Resuming events in your Windows Store app.

The Windows.UI.WebUI.WebUIApplication.Activated event will be fired when your app is being launched. Windows.UI.WebUI.WebUIApplication.Activated gives your app the opportunity to restore the last state the user saw it in. It also allows you to acquire any activation parameters passed to you by the system. Windows.UI.WebUI.WebUIApplication.Activated may also fire while your app is running if there are new activation parameters for your app to respond to.

The Windows.UI.WebUI.WebUIApplication.Suspending event fires whenever your app is being suspended by the system. Windows.UI.WebUI.WebUIApplication.Suspending gives your app the opportunity to save the user’s current session so that it can be restored in the case that your app is terminated. You can also use this event to free exclusive system resources like files or references to external devices.

The Windows.UI.WebUI.WebUIApplication.Resuming event fires whenever your app is woken up from the suspended state. Because your app can stay suspended for hours or even days, it’s possible that data within your app has gone stale. Windows.UI.WebUI.WebUIApplication.Resuming gives your app the opportunity to refresh this stale data. Note that you do not have to restore saved state during resume. Windows.UI.WebUI.WebUIApplication.Resuming keeps your app in memory so your app’s previous state is still loaded.

Windows attempts to keep as many suspended apps in memory as possible. By keeping these apps in memory, Windows ensures that users can quickly and reliably switch between suspended apps. However, if there aren't enough resources to keep your app in memory, Windows can terminate your app. Note that apps don't receive notification that they are being terminated, so the only opportunity you have to save your app's data is during suspension. When an app determines that it is activated after being terminated, it should load the application data that it saved during suspend so that the app appears as it did when it was suspended.

Generally, users don't need to close apps, they can let Windows manage them. However, a user can choose to close an app. There's no special event to indicate that the user has closed an app. After an app has been closed by the user, it's suspended and terminated.

To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.

To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.


Note  For Windows 8 app samples, download the Windows 8 app samples pack. The samples in the Windows 8 app samples pack will build and run only on Microsoft Visual Studio 2012.


Related topics

Windows 8 app samples
How to activate an app (JavaScript)
How to activate an app (C#/VB/C++)
How to suspend an app (JavaScript)
How to suspend an app (C#/VB/C++)
How to resume an app (JavaScript)
How to resume an app (C#/VB/C++)
Guidelines for app suspend and resume
Application lifecycle

Operating system requirements

Windows 8.1
Windows Server 2012 R2

Build the sample

  1. Start Visual Studio 2013 and select File > Open > Project/Solution.
  2. Go to the directory in which you unzipped the sample. Go to the directory named for the sample, and double-click the Microsoft Visual Studio Solution (.sln) file.
  3. Press F7 or use Build > Build Solution to build the sample.

Run the sample

To debug the app and then run it, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.