我正在 windows phone 10 中开发应用程序
出于某种原因,我必须处理应用程序状态(进入后台,进入前台)。我在 App.xaml.cs 处理了事件挂起和恢复,但它不起作用,没有达到 OnSuspending 和 OnResuming。请帮我检查我的源代码并告诉我如何处理这些事件。
这是我的代码:
public App()
{
Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
Microsoft.ApplicationInsights.WindowsCollectors.Session);
this.InitializeComponent();
this.Suspending += OnSuspending;
Application.Current.Suspending += new SuspendingEventHandler(OnSuspending);
Application.Current.Resuming += new EventHandler<Object>(OnResuming);
}
private void OnSuspending(Object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
private void OnResuming(object sender, object e)
{
// do some thing
}