protected override void OnLaunched(LaunchActivatedEventArgs args)
{
// TODO: Create a data model appropriate for your problem domain to replace the sample data
var sampleData = new SampleDataSource();
if (args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser)
{
//TODO: Load state from previously suspended application
}
// Create a Frame to act navigation context and navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
var rootFrame = new Frame();
rootFrame.Navigate(typeof(GroupedItemsPage), sampleData.ItemGroups);
// Place the frame in the current Window and ensure that it is active
Window.Current.Content = rootFrame;
Window.Current.Activate();
}
从上面的代码中可以看到,在应用程序再次被启动时,OnLaunched事件参数中可以得到一个ApplicationExecutionState枚举类型,从中可以得到应用程序在这之前是什么状态。
此枚举类型的详细内容:
namespace Windows.ApplicationModel.Activation
{
// Summary:
// Specifies the current execution state of the app.
public enum ApplicationExecutionState
{
// Summary:
// The app is not running.
NotRunning = 0,
//
// Summary:
// The app is running.
Running = 1,
//
// Summary:
// The app is suspended.
Suspended = 2,
//
// Summary:
// The app was terminated after being suspended.
Terminated = 3,
//
// Summary:
// The app was closed by the user.
ClosedByUser = 4,
}
}