How to activate an app (Windows Store apps using C#/VB/C++ and XAML)
Learn how to define the activation experience for your Windows Store app. The example in this topic overrides the OnLaunched method.
Roadmap: How does this topic relate to others? See:
The Windows.UI.Xaml.Application class defines methods you can override to handle the various activation types. Several of the activation types have a specific method that you can override. For the other activation types, override the OnActivated method.
Define the class for your application.
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="AppName.App" >
Class App Protected Overrides Sub OnLaunched(args As LaunchActivatedEventArgs) Window.Current.Content = New MainPage() Window.Current.Activate() End Sub End Class
When the user switches to your terminated app, the system sends the Activated event, with Kind set to Launch and PreviousExecutionState set to Terminated or ClosedByUser. The app should load its saved application data and refresh its displayed content.
Protected Overrides Sub OnLaunched(args As Windows.ApplicationModel.Activation.LaunchActivatedEventArgs) Dim restoreState As Boolean = False Select Case args.PreviousExecutionState Case ApplicationExecutionState.Terminated ' TODO: Populate the UI with the previously saved application data restoreState = True Case ApplicationExecutionState.ClosedByUser ' TODO: Populate the UI with the previously saved application data restoreState = True Case Else ' TODO: Populate the UI with defaults End Select Window.Current.Content = New MainPage(restoreState) Window.Current.Activate() End Sub
If the value of PreviousExecutionState is NotRunning, the app failed to save its application data successfully and the app should start over as if it were being initially launched.
- How to suspend an app
- How to resume an app
- Application lifecycle
- Guidelines for app suspend and resume