如何在Windows Phone 7和8中获取应用程序状态事件?

时间:2014-11-26 10:36:20

标签: windows-phone-7 windows-phone-8

我正在创建一个应用程序,每当应用程序状态发生变化(即Paused,Stop,Start,InBackground)时,我想保存一些数据用于分析目的,并对我的服务器进行http调用。 我做了r& d但没有任何相关的东西。 任何解决方案都将不胜感激。

感谢。

2 个答案:

答案 0 :(得分:1)

App.xaml.cs文件中查找描述您要跟踪的内容的事件处理程序。我会在这里发布它们以供参考。您可以根据这些事件的触发来跟踪应用程序的状态。我应该注意,其中一些事件确实有时间限制,因此在其中运行cpu密集型例程通常不是一个好主意。

// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}

// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}

// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}

答案 1 :(得分:0)

在App.xaml.cs中,有启动,激活,停用和关闭的事件。您可以在这些事件中编写代码以保存数据。

请参阅此处http://msdn.microsoft.com/en-us/library/windows/apps/ff817008%28v=vs.105%29.aspx