(Windows Phone 10)处理应用程序状态

时间:2016-05-12 11:32:54

标签: c# win-universal-app resume suspend application-state

我正在开发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
    }

0 个答案:

没有答案