我正在開發Windows Phone 10中的應用程序(Windows phone 10)Handle應用程序狀態
由於某些原因,我必須處理應用程序狀態(轉到後臺,輸入前臺)。我有處理事件暫停和繼續在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
}
如果您嘗試調試它,通常你會不會觸發這些事件 - 你將不得不使用*生命週期選項卡* - [看到這個問題](http://stackoverflow.com/q/24103101/2681948)獲得更多幫助。 – Romasz