Windows页面上的Windows Phone应用程序停用检测

时间:2013-03-04 05:20:19

标签: windows-phone-8 tombstoning

我正在使用Windows Phone。当我的应用程序停用并进入后台时,我想检测OnNavigatedFrom事件上的应用程序停用,以便我可以在应用程序进入后台时实现某些逻辑。我怎么能这样做?????

3 个答案:

答案 0 :(得分:1)

我自己找到了解决方案。将处理程序附加到您导航的页面上的PhoneApplicationService.Current.Deactivated事件。

答案 1 :(得分:1)

您可以节省从APP事件或页面事件中停用的时间,并将其存储在IsolatedStorage中,然后在您的应用重新激活时检索数据(OnNavigatedTo)。

答案 2 :(得分:0)

使用以下方法(在App.xaml.cs文件中找到)在应用程序激活或停用时执行逻辑:

// 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)
{

}